Skip to content

feat: add support SELECT all columns from function result #2207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

0xlianhu
Copy link
Contributor

@0xlianhu 0xlianhu commented Mar 26, 2025

PostgreSQL supports composite type expansion using .*, for example, below query is valid in PostgreSQL:

SELECT (pg_stat_file('postgresql.conf')).*

More generic one is like below one in queries or sub-queries:

SELECT (function_name(param1, ... paramN)).* FROM my_table ...

There might be multiple duplicated parentheses surround the function call, such as:

SELECT (((pg_stat_file('postgresql.conf')))).* -- this is same effect as one `()` surrounding

The PR is adding the support to parse/deparse this type of SQLs.

PostgreSQL supports composite type expansion using .*,
for example below query is valid in PostgreSQL:
SELECT (pg_stat_file('postgresql.conf')).*
@manticore-projects
Copy link
Contributor

Beautifully executed! Well done and thank you much for your effort and contribution.

@manticore-projects manticore-projects merged commit 30cf5d7 into JSQLParser:master Mar 26, 2025
3 of 4 checks passed
@manticore-projects
Copy link
Contributor

Greetings!

Unfortunately, I found out that commit 30cf5d7 causes a huge performance deterioration:

(version)  Mode  Cnt    Score    Error  Units
   latest  avgt    3   81.637 ± 21.386  ms/op <-- `FunctionAllColumns()` commented out
      5.2  avgt    3  393.523 ± 54.199  ms/op <-- release w/ `FunctionAllColumns()`
      5.1  avgt    3   86.419 ± 22.178  ms/op <-- release w/o `FunctionAllColumns()`

This toll is not acceptable for a rather exotic feature only and I am going to disable it.
Although all code is still there and only the call of FunctionAllColumns() in PrimaryExpression has been commented out.

You are welcome to refactor your code and I will most happily accept it again once performance can be proved.

Recommendations:

  1. try to avoid the syntactic Lookahead
  2. your (((( FUNCTION )))).* is nothing else but a ParenthesedExpressionList with just one parameter of type Function, followed by ".". So maybe parse for a possible extension by "." at the end of a ParenthesedExpressionList when it has only one single Function element.

I am open for discussion of course.
Best and cheers!

manticore-projects added a commit that referenced this pull request May 13, 2025
- optimise the `LOOKAHEAD`, avoid syntactic lookaheads

- disable `FunctionAllColumns()` in `PrimaryExpression` related to #2207

Signed-off-by: Andreas Reichel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants