'How to INSERT now() + INTERVAL in Postgres 9.x
I'm trying to INSERT
a future date into a timestamp with time zone
column in a table in Postgres 9.6.2. I'd like this date to be the current transaction time plus an arbitrary interval, such as 1 hour.
I understand how to do date/time arithmetic in a SELECT
statement, but the same syntax of NOW() + INTERVAL '1 hour'
does not seem to be valid in an INSERT
statement.
Aside from accomplishing this at the application level, is it possible to accomplish this using a single INSERT
statement using date/time arithmetic? If not, what would best practice be in this situation?
Solution 1:[1]
I think you have it right - this worked for me:
insert into barcode (id,barcode,active,created,updated)
values (111,'23432', true, NOW() + INTERVAL '1 hour',NOW());
I am running Postgres 9.4.13.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | user2182349 |