'Wrong datetime value for now() function
I have a question. I'm writing a program in springu and jpa / hibernate. database which i use is PostgreSQL. I have simple table with 2 column: first with type "timestamp with time zone" and second with type "timestamp without time zone". In my model those column have "LocalDateTime" type. I use nativeQuery from JpaRepository like this:
@Modifying
@Query(value = "INSERT INTO public.tempor(id, date1, date2) VALUES (2, now(), now());", nativeQuery = true)
void saveTransaction();
After inserting this to database first column have correct value from datebase datetime, but second is set as my localhost datetime. Why and how to solve this problem? Thanks for helps.
Solution 1:[1]
You can use CURRENT_TIMESTAMP for example:
INSERT into tempor (id,date1)
VALUES (1, current_timestamp);
second option, you can make the default value for your column as now():
alter table tempor alter date1 set default now();
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 | Med Elgarnaoui |
