Reputation: 1716
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?
Upvotes: 5
Views: 6674
Reputation: 40491
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.
Upvotes: 5
Reputation: 2617
Maybe the error comes from using the wrong function. Try this instead:
UPDATE USERS SET LAST_LOGIN = CURRENT_TIMESTAMP WHERE USER_NAME = ?
Upvotes: 1