Skip to content

[Feature Request] Support native date.now function in standard library to reduce S-string usage #5720

@sunyeongchoi

Description

@sunyeongchoi

What's up?

Description

Currently, many temporal functions, including date.now, are not natively supported in PRQL's standard library. To use them, users must resort to S-strings like s"now()" or s"CURRENT_TIMESTAMP".

While S-strings provide a powerful escape hatch, they have several drawbacks:

  1. Poor Readability: They break the visual flow of PRQL code.

  2. Maintenance: They make the query dialect-dependent, defeating one of PRQL's core strengths (abstraction over SQL dialects).

  3. Developer Experience: Writing s"now()" feels less intuitive than a native function call.

Proposed Change

I propose adding a native date.now function to the PRQL standard library. This would allow users to write:

derive [
  created_at = date.now
]

Instead of:

derive [
  created_at = s"now()"
]

Implementation Idea

The date.now function can be added to the stdlib.prql and mapped to the appropriate SQL equivalent based on the target dialect (e.g., NOW() for PostgreSQL/MySQL, CURRENT_TIMESTAMP for others).

I am willing to contribute to this by implementing the date.now function in the standard library if the maintainers agree with this direction.

Additional Context
As PRQL matures, moving frequently used functions from S-strings to the standard library will significantly improve the overall user experience and type-safety potential.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions