Skip to content

[BUG] JSQLParser Version 5.4-Snapshot : PostgreSQL : 2nd Function Parameter with schema/table/column can't be parsed #2290

Closed

Description

@davyboyhayes

Failing SQL Feature:

  • Using a function with more than one parameter, where the second parameter includes schema.table.column, with an addition to an Interval, can't be parsed. However, if the same parameter is used as a singular parameter, or the same multi-parameter function is used without schema, the SQL can be parsed.

SQL Example:

  • Simplified Query Example, focusing on the failing feature
SELECT
  DATE_TRUNC(
  'week',
    (
      "schema"."tbl"."column" + INTERVAL '1 day'
    )
  )
FROM
"schema"."tbl";

Note that:

SELECT
DATE_TRUNC(
'week',
  (
    "tbl"."column" + INTERVAL '1 day'
  )
)
FROM
"schema"."tbl";

and

SELECT
  FUNC(
    (
      "schema"."tbl"."column" + INTERVAL '1 day'
    )
  )
FROM
"schema"."tbl";

both work

Image

Software Information:

  • JSqlParser 5.4-Snapshot (f10b52e)
  • PostgreSQL

Activity

  1. davyboyhayes commented on Aug 5, 2025

    @davyboyhayes
    ContributorAuthor

    Again, I'm more than happy to take a steer on where I would need to make a change, and put a PR up

  2. davyboyhayes commented on Aug 5, 2025

    @davyboyhayes
    ContributorAuthor
    SELECT
      DATE_TRUNC(
      'week',
      "schema"."tbl"."column" + INTERVAL '1 day'
      )
    FROM
    "schema"."tbl";

    When there isn't parenthesis wrapping the second function, this parses. Problem is Metabase auto generates this SQL with parenthesis when trying to group records by week (and you have the week configured to start on a Monday - hence the interval addition)

  3. davyboyhayes commented on Aug 11, 2025

    @davyboyhayes
    ContributorAuthor

    @manticore-projects - do you have any hints where I could take a look please?

  4. manticore-projects commented on Aug 11, 2025

    @manticore-projects
    Contributor

    Greetings.

    Best thing was enabling Token Debug mode in the Grammar and then run the specific test to see where/why it parses wrongly.

  5. davyboyhayes commented on Aug 11, 2025

    @davyboyhayes
    ContributorAuthor

    Thanks, I'll give that a try!

  6. davyboyhayes commented on Aug 11, 2025

    @davyboyhayes
    ContributorAuthor

    Simplifying this further:

    SELECT f('x',(s.t.c + INTERVAL '1 day')) FROM s.t;

    It is trying to convert (s.t.c + INTERVAL '1 day') into a ParenthesedColumnList which then breaks because + makes no sense in a column list. However, this isn't a column list, but a parenthesed expression

  7. davyboyhayes commented on Aug 11, 2025

    @davyboyhayes
    ContributorAuthor
    	at net.sf.jsqlparser@5.4-SNAPSHOT/net.sf.jsqlparser.parser.CCJSqlParser.generateParseException(CCJSqlParser.java)
    	at net.sf.jsqlparser@5.4-SNAPSHOT/net.sf.jsqlparser.parser.CCJSqlParser.jj_consume_token(CCJSqlParser.java)
    	at net.sf.jsqlparser@5.4-SNAPSHOT/net.sf.jsqlparser.parser.CCJSqlParser.ParenthesedColumnList(CCJSqlParser.java:22396)
    	at net.sf.jsqlparser@5.4-SNAPSHOT/net.sf.jsqlparser.parser.CCJSqlParser.LambdaExpression(CCJSqlParser.java:28655)
    	at net.sf.jsqlparser@5.4-SNAPSHOT/net.sf.jsqlparser.parser.CCJSqlParser.ComplexExpressionList(CCJSqlParser.java:22425)
    	at net.sf.jsqlparser@5.4-SNAPSHOT/net.sf.jsqlparser.parser.CCJSqlParser.ExpressionList(CCJSqlParser.java:22265)
    	at net.sf.jsqlparser@5.4-SNAPSHOT/net.sf.jsqlparser.parser.CCJSqlParser.InternalFunction(CCJSqlParser.java:29592)
    	at net.sf.jsqlparser@5.4-SNAPSHOT/net.sf.jsqlparser.parser.CCJSqlParser.Function(CCJSqlParser.java:29475)
    
  8. davyboyhayes commented on Aug 11, 2025

    @davyboyhayes
    ContributorAuthor

    Not sure if this is too much of a degredation of performance. (JMH numbers are in the PR), so if you have a different way of achieving this, I'd be happy to take a look.

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