Skip to content

Issue parsing postgres timestamptz as expression #1619

Closed

Description

@tpoll

Postgres has syntax that allows you to write a query such as:

SELECT * from table where x >= timestamptz '2021-07-05 00:00:00+00'

This fails to parse with an exception

Caused by: net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "\'2021-07-05 00:00:00+00\'" <S_CHAR_LITERAL>
    at line 1, column 44.

Interestingly SELECT * from table where x >= timestamptz('2021-07-05 00:00:00+00') (note the parens) does parse.

I also tested SELECT * from table where x >= timestamp '2021-07-05 00:00:00+00' which does properly parse.

I'm not too familiar with the parsing grammar, but it seems like maybe timestamptz just needs to be treated similarly to timestamp?

Happy to open up a PR if someone can point me in the right direction to get started.

Activity

  1. changed the title [-]Issue parsing postgres timestamptz [/-] [+]Issue parsing postgres timestamptz as expression[/+] on Aug 18, 2022
  2. manticore-projects commented on Aug 19, 2022

    @manticore-projects
    Contributor

    Greetings @tpoll. Thank you for considering to solve it by yourself.

    You would need to:

    1. Edit the JavaCC Grammar and add your new Token
    2. Add a Test Case to Parse and Deparse your statement
    3. Run all Tests to ensure, that everything is still working
      4( Submit your PR

    (Usually there is more to do, but in this case just adding a token could do.)

  3. manticore-projects commented on Aug 19, 2022

    @manticore-projects
    Contributor

    Interestingly SELECT * from table where x >= timestamptz('2021-07-05 00:00:00+00') (note the parens) does parse.

    Simply because Anything(...) is parsed as a Function() (without understanding the particular means or purpose of Anything).
    But since timestamptz '2021-07-05 00:00:00+00' does not match a Function() and not any allowed DATE_TIME_LITERAL you will need to declare it in the Grammar.

  4. tpoll commented on Aug 19, 2022

    @tpoll
    ContributorAuthor

    Thanks for the pointers @manticore-projects. I opened up a PR which I believe should safely add support.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions