Skip to content

support column definition list in table alias for postgres #1524

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

Closed
lovasoa opened this issue Nov 15, 2024 · 1 comment · Fixed by #1526
Closed

support column definition list in table alias for postgres #1524

lovasoa opened this issue Nov 15, 2024 · 1 comment · Fixed by #1526

Comments

@lovasoa
Copy link
Contributor

lovasoa commented Nov 15, 2024

Postgres supports specifying column names AND types in a table alias (after AS) for functions that return values of type "record".

The following syntax is valid in postgres

SELECT * FROM jsonb_to_record('{"a": "x", "b": 2}'::jsonb) AS x(a TEXT, b INT);

But in sqlparser, it returns

Expected: ), found: TEXT

This was initially reported in SQLPage, as: sqlpage/SQLPage#690

@lovasoa
Copy link
Contributor Author

lovasoa commented Nov 15, 2024

From https://www.postgresql.org/docs/17/queries-table-expressions.html#QUERIES-TABLEFUNCTIONS :

In some cases it is useful to define table functions that can return different column sets depending on how they are invoked. To support this, the table function can be declared as returning the pseudo-type record with no OUT parameters. When such a function is used in a query, the expected row structure must be specified in the query itself, so that the system can know how to parse and plan the query. This syntax looks like:

function_call [AS] alias (column_definition [, ... ])
function_call AS [alias] (column_definition [, ... ])
ROWS FROM( ... function_call AS (column_definition [, ... ]) [, ... ] )

lovasoa added a commit to lovasoa/sqlparser-rs that referenced this issue Nov 15, 2024
```sql
SELECT * FROM some_fun() AS x (a TEXT, b INT)
```

fixes apache#1524
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 a pull request may close this issue.

1 participant