问题
I want to create user or change password with a timestamp calculated over current time. example:
# CREATE USER user WITH PASSWORD 'password12345678' VALID UNTIL '(NOW() + interval 1 month)';
of course it's not valid:
ERROR: invalid input syntax for type timestamp with time zone: "(NOW() + interval 1 month)"
回答1:
Utility commands like CREATE USER do not accept expressions, only literals. You need dynamic SQL.
DO
$do$
BEGIN
EXECUTE format($$CREATE USER myuser WITH PASSWORD 'password12345678' VALID UNTIL %L$$, NOW() + interval '1 month');
END
$do$;
Detailed explanation:
- Creating user with password from variables in anonymous block
回答2:
I am not familiar with postgresql but from a quick google search it appears you want the following:
CURRENT_DATE + INTERVAL '1 month';
来源:https://stackoverflow.com/questions/54482903/set-valid-until-value-with-a-calculated-timestamp