I would like to insert TIMESTAMP into column LAST_LOGIN
CREATE TABLE USER(
ID INTEGER NOT NULL,
USER_NAME TEXT,
FIRST_NAME TEXT,
LAST_NAME TEXT,
LAST_LOGIN DATE,
DATE_REGISTERED DATE,
ROLE INTEGER,
CAN_LOGIN INTEGER
)
;
ALTER TABLE USER ADD CONSTRAINT KEY1 PRIMARY KEY (ID)
;
I tried this:
UPDATE USERS SET LAST_LOGIN = TIMESTAMP WHERE USER_NAME = ?
But I get org.postgresql.util.PSQLException: ERROR: column "timestamp" does not exist Position: 31
What is the correct way to insert current time into table column LAST_LOGIN?
TIMESTAMP
is not a known function is POSTGRES
, therefore, it recognize it as a column .
POSTGRES
dates/time functions:
NOW();
current_date;
current_time;
current_timestamp;
So your correct query should be
UPDATE USERS SET LAST_LOGIN = now() WHERE USER_NAME = ?
You can read all about postgres time/date functions in this document.
Maybe the error comes from using the wrong function. Try this instead:
UPDATE USERS SET LAST_LOGIN = CURRENT_TIMESTAMP WHERE USER_NAME = ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With