Hello,
2. Run statement UPDATE t_update SET F1 = (CASE WHEN (CURRENT_TIMESTAMP IS NULL ) THEN (CURRENT_TIMESTAMP ) ELSE (CURRENT_TIMESTAMP ) END)
Result: No exceptions.
Trying to find a way to perform a CASE statement without needing to typecast. Research so far suggests that this is not possible, but I wanted to check with the PSQL community to be sure.
Steps:
1. CREATE TABLE t_update (F1 timestamp(6) NULL )
1. CREATE TABLE t_update (F1 timestamp(6) NULL )
2. Run statement UPDATE t_update SET F1 = (CASE WHEN (CURRENT_TIMESTAMP IS NULL ) THEN (CURRENT_TIMESTAMP ) ELSE (CURRENT_TIMESTAMP ) END)
Result: No exceptions.
3. Run parametrised statement
UPDATE t_update SET F1 = (CASE WHEN (? IS NULL ) THEN (? ) ELSE (? ) END)
UPDATE t_update SET F1 = (CASE WHEN (? IS NULL ) THEN (? ) ELSE (? ) END)
Result: Error
ERROR: VERROR; column "f1" is of type timestamp without time zone but _expression_ is of type text(Hint You will need to rewrite or cast the _expression_.; Position 27; File d:\pginstaller.auto\postgres.windows-x64\src\backend\parser\parse_target.c; Line 591; Routine transformAssignedExpr; ) (6822148)
ERROR: VERROR; column "f1" is of type timestamp without time zone but _expression_ is of type text(Hint You will need to rewrite or cast the _expression_.; Position 27; File d:\pginstaller.auto\postgres.windows-x64\src\backend\parser\parse_target.c; Line 591; Routine transformAssignedExpr; ) (6822148)
NOTE: From my research online, I found that typecasting works and also the error from the database suggests typecasting.
This statement works:
UPDATE t_update SET F1 = (CASE WHEN (?::timestamp(6) IS NULL ) THEN (?::timestamp(6) ) ELSE (?::timestamp(6) ) END)
This statement works:
UPDATE t_update SET F1 = (CASE WHEN (?::timestamp(6) IS NULL ) THEN (?::timestamp(6) ) ELSE (?::timestamp(6) ) END)
Please let me know your thoughts.
Many thanks!
Anthony