Skip to content

now_ or currentTimestamp_ in UTCTime #823

Description

@kushagarr

Why do now_ and currentTimestamp_ use LocalTime in Beam?

In PostgreSQL, now() and CURRENT_TIMESTAMP return a timestamp with time zone.

However, in Beam:

  • now_ from beam-postgres has a LocalTime-based type.

  • currentTimestamp_ from beam-core also produces LocalTime.

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:

  1. use PostgreSQL’s now() or CURRENT_TIMESTAMP for a UTCTime column;

  2. cast or convert the expression safely inside the Beam query; or

  3. 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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking changeChange will require a major version bumpbug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions