Search Postgresql Archives

How to handle CASE statement with PostgreSQL without need for typecasting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

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 )

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)

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)  


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)   


Please let me know your thoughts.

Many thanks!
Anthony

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux