Skip to content

Postgres: Parse trailing asterisk after table name in FROM clause - #2525

Open
BenSatori wants to merge 2 commits into
apache:mainfrom
BenSatori:postgres-tbl-name-trailing-asterisk
Open

BenSatori wants to merge 2 commits into
apache:mainfrom
BenSatori:postgres-tbl-name-trailing-asterisk

Conversation

@BenSatori

Copy link
Copy Markdown
Contributor

Before this PR, PostgreSQL's FROM tbl_name* syntax (asterisk explicitly indicating that descendant tables should be included) failed to parse:

SELECT * FROM tbl_name*

This was already supported for TRUNCATE TABLE name* and LOCK TABLE name*, but not for regular FROM items.

Docs: https://www.postgresql.org/docs/current/sql-select.html#SQL-FROM

Fix

  • Added a has_trailing_asterisk field to TableFactor::Table, parsed the same way as the existing asterisk handling in TRUNCATE/LOCK TABLE.
  • Renamed the pre-existing has_asterisk fields on TruncateTableTarget and LockTableTarget to has_trailing_asterisk for naming consistency.

This PR was created with AI assistance.

PostgreSQL allows an explicit trailing '*' after a table name in FROM
to indicate that descendant tables should be included, e.g.
SELECT * FROM tbl_name*. This was previously only supported for
TRUNCATE and LOCK TABLE targets, not for FROM items.

Also renamed the existing has_asterisk fields on TruncateTableTarget
and LockTableTarget to has_trailing_asterisk for consistency and
clarity.

https://www.postgresql.org/docs/current/sql-select.html#SQL-FROM
@BenSatori
BenSatori force-pushed the postgres-tbl-name-trailing-asterisk branch from f934ecd to 2813477 Compare September 23, 2026 13:41
Comment thread src/ast/query.rs
Comment on lines 2234 to +2239
if let Some(json_path) = json_path {
json_path.fmt(f)?;
}
if *has_trailing_asterisk {
write!(f, "*")?;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should render the * before json_path, matching the parse order. On Snowflake and Redshift (supports_partiql), SELECT * FROM t*[0] renders as SELECT * FROM t[0]*, which fails to parse back with Expected: end of statement, found: *.

Suggested change
if let Some(json_path) = json_path {
json_path.fmt(f)?;
}
if *has_trailing_asterisk {
write!(f, "*")?;
}
if *has_trailing_asterisk {
write!(f, "*")?;
}
if let Some(json_path) = json_path {
json_path.fmt(f)?;
}

Comment thread src/parser/mod.rs
Comment on lines +16723 to +16725
// Postgres/Snowflake: `FROM tab*` explicitly includes descendant tables.
// https://www.postgresql.org/docs/current/sql-select.html#SQL-FROM
let has_trailing_asterisk = self.consume_token(&Token::Mul);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could drop this comment. Snowflake's FROM grammar has no tab* form, and the has_trailing_asterisk field doc already links the Postgres reference.

Suggested change
// Postgres/Snowflake: `FROM tab*` explicitly includes descendant tables.
// https://www.postgresql.org/docs/current/sql-select.html#SQL-FROM
let has_trailing_asterisk = self.consume_token(&Token::Mul);
let has_trailing_asterisk = self.consume_token(&Token::Mul);

@LucaCappelletti94 LucaCappelletti94 added the waiting on contributor The review needs further refinements by its author label Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PostgreSQL waiting on contributor The review needs further refinements by its author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants