GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — PostgreSQL JSON arrow operators · Issue #1696 · JSQLParser/JSqlParser

PostgreSQL JSON arrow operators #1696

New issue
Copy link
New issue
Copy link
Closed
#1676
Closed
PostgreSQL JSON arrow operators#1696
#1676
Copy link

Description

@juliencorman
juliencorman
opened on Dec 15, 2022
Issue body actions

Hello,

With the JSQL Parser Version 4.5, I encountered the two following issues when parsing PostgreSQL JSON functions in infix notation (the "arrow" operators).

The query
SELECT '{"key": "value"}'::json -> 'key' AS X
yields an exception
net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "->" "->".

This extends to all the combinations that I tried for the pattern
SELECT [leftOperand]::[datatype] [arrowSymbol] [rightOperand] AS X
where
[leftOperand] is a json object
[datatype] is one of {json, jsonb}
[arrowSymbol] is one of { ->, ->>, #>, #>>}
[rightOperand] is a positive integer, a quoted string or a an expression of the form '{a,b}'.

The query
SELECT Y::json -> 'key' AS X
is parsed.

As well as all the combinations that I tried for the above pattern, but where is a non-quoted string (aka a variable name).

The expression
Y::json -> 'key'
in this example is exposed as an instance of
net.sf.jsqlparser.expression.JSONExpression.

And the right operand ('key' in this example) is the first element of the list
net.sf.jsqlparser.expression.JSONExpression.idents.

However, this list idents has private access.
And looking at the source code, I could not find a way to retrieve its elements.
The class JSONExpression contains a getter method for idents, but the code has been commented out.

Thank you in advance for your help.

Kind regards,
Julien Corman

Activity

  1. manticore-projects commented on Dec 15, 2022

    @manticore-projects
    manticore-projects
    on Dec 15, 2022
    Contributor
    More actions
    SELECT '{"key": "value"}'::json -> 'key' AS X

    fails because JSONExpression is currently defined for Column only (but not for an Expression).
    Please refere to the source JSQLParser/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt:4175

  2. manticore-projects
    added a commit that references this issue on Dec 16, 2022

    fix: fix JSonExpression, accept Expressions

    This issue will close once commit 1ce014a is merged into the 'master' branch.
    1ce014a
  3. manticore-projects commented on Dec 16, 2022

    @manticore-projects
    manticore-projects
    on Dec 16, 2022
    Contributor
    More actions

    Greetings,

    I have fixed that, although we can't make it work with a generic function:

    -- won't work
    SELECT myStringFunction(a, b, c)::json -> 'key' AS X

    The parser will become way too slow and many performance related tests will fail.
    Although Parameters and Sub-Queries are supported.

    I have also exposed the Idents() and Operators(), no idea what happened there.

  4. juliencorman commented on Dec 16, 2022

    @juliencorman
    juliencorman
    on Dec 16, 2022
    Author
    More actions

    Great, thank you very much!

    Kind regards,
    Julien Corman

  5. juliencorman
    closed this as completedon Dec 16, 2022
  6. manticore-projects
    reopened this on Dec 16, 2022
  7. manticore-projects commented on Dec 16, 2022

    @manticore-projects
    manticore-projects
    on Dec 16, 2022
    Contributor
    More actions

    Please wait for the PR #1676 to get accepted. This will close the Issue automatically.
    In the meantime you can pull from that branch yourself and compile from source.
    Only @wumpz can accept PRs.

  8. wumpz
    closed this as completedin #1676on Dec 22, 2022
  9. wumpz
    added a commit that references this issue on Dec 22, 2022

    Assorted Fixes #4 (#1676)

    This issue will close once commit 8d9db70 is merged into the 'master' branch.
    8d9db70
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

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.