# How can I write data of type INTERVAL to PostgreSQL database?

**URL:** <https://forum.inductiveautomation.com/t/how-can-i-write-data-of-type-interval-to-postgresql-database/69058>\
**Category:** Ignition\
**Tags:** database, scripting\
**Created:** [January 26, 2023, 9:27pm UTC](https://forum.inductiveautomation.com/t/how-can-i-write-data-of-type-interval-to-postgresql-database/69058 "2023-01-26T21:27:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Seamus\_Gallagher](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@Seamus\_Gallagher](https://forum.inductiveautomation.com/u/Seamus_Gallagher)\
**Post date:** [January 26, 2023, 9:27pm UTC](https://forum.inductiveautomation.com/t/how-can-i-write-data-of-type-interval-to-postgresql-database/69058/1 "2023-01-26T21:27:14Z")

</div>

Hello, @PGriffith  
I've searched for an answer to this question but it seems nobody has asked it.

How do you write time interval data to a Postgres database column of type INTERVAL using Ignition scripting?  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/2/a2937bbf885ebe0f359ac16f222a590a32e7a9f5.png)

In scripting, I would like to run a command like this:

```auto
import datetime
runtime = datetime.timedelta(seconds=300)
databaseConnection = "my_DB"
SQL = 'INSERT INTO example_db (runtime) VALUES (?);'
system.db.runPrepUpdate(sql, (runtime,), databaseConnection)

```

In my experience with Python 3.X, this should work fine.

However, it always returns an unhelpful error message:

```auto
postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of org.python.core.PyObjectDerived. Use setObject() with an explicit Types value to specify the type to use.
at org.postgresql.jdbc.PgPreparedStatement.setObject(PgPreparedStatement.java:1009)

```

What does this error message mean?  
And how can I write timedelta data to Postgres? Is there some kind of limitation with Jython here?

Thank you

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [January 26, 2023, 9:53pm UTC](https://forum.inductiveautomation.com/t/how-can-i-write-data-of-type-interval-to-postgresql-database/69058/2 "2023-01-26T21:53:51Z")

</div>

EDIT: DOH! Forgot to welcome you to the forums... sorry 'bout that...

Intervals are not a standard JDBC data type.

```python
db = 'Test'

seconds = 300

query = "INSERT INTO interval_table (runtime) VALUES (?::interval)"

system.db.runPrepUpdate(query, ['{} SECONDS'.format(seconds)], db)

```
