Why do now_ and currentTimestamp_ use LocalTime in Beam?
In PostgreSQL, now() and CURRENT_TIMESTAMP return a timestamp with time zone.
However, in Beam:
This becomes problematic when the application’s data model uses UTCTime.
For example, I am building a CTE-based statement containing multiple inserts and updates. One insert returns some values that are then used as part of the input to a subsequent insert. For timestamp columns, I want PostgreSQL to generate the value using now() or CURRENT_TIMESTAMP.
I cannot use default_ in this particular query shape, so I need to include the timestamp expression explicitly. However, because Beam represents these expressions as LocalTime, I cannot use them for a column whose Haskell type is UTCTime.
This makes it difficult to construct dynamic, composable insert and update queries while still relying on the database clock.
Why are now_ and currentTimestamp_ represented as LocalTime rather than UTCTime in Beam?
Is there a recommended way to:
-
use PostgreSQL’s now() or CURRENT_TIMESTAMP for a UTCTime column;
-
cast or convert the expression safely inside the Beam query; or
-
we can introduce some new UTCTime compatible functions which can be used to satisfy the types, since these are pure renderings for the sql anyway and have nothing to do in haskell codebase?
Why do
now_andcurrentTimestamp_useLocalTimein Beam?In PostgreSQL,
now()andCURRENT_TIMESTAMPreturn a timestamp with time zone.However, in Beam:
now_frombeam-postgreshas aLocalTime-based type.currentTimestamp_frombeam-corealso producesLocalTime.This becomes problematic when the application’s data model uses
UTCTime.For example, I am building a CTE-based statement containing multiple inserts and updates. One insert returns some values that are then used as part of the input to a subsequent insert. For timestamp columns, I want PostgreSQL to generate the value using
now()orCURRENT_TIMESTAMP.I cannot use
default_in this particular query shape, so I need to include the timestamp expression explicitly. However, because Beam represents these expressions asLocalTime, I cannot use them for a column whose Haskell type isUTCTime.This makes it difficult to construct dynamic, composable insert and update queries while still relying on the database clock.
Why are
now_andcurrentTimestamp_represented asLocalTimerather thanUTCTimein Beam?Is there a recommended way to:
use PostgreSQL’s
now()orCURRENT_TIMESTAMPfor aUTCTimecolumn;cast or convert the expression safely inside the Beam query; or
we can introduce some new UTCTime compatible functions which can be used to satisfy the types, since these are pure renderings for the sql anyway and have nothing to do in haskell codebase?