feat(postgres): add identity/schema niladic functions to bare_functions#2677
Open
skyf0l wants to merge 1 commit into
Open
feat(postgres): add identity/schema niladic functions to bare_functions#2677skyf0l wants to merge 1 commit into
skyf0l wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PostgreSQL allows a set of SQL-standard niladic functions to be called without parentheses —
current_schema,current_user,current_catalog,current_role,session_user,system_user, anduser. sqruff'spostgresdialect only registered the date/time niladic functions (current_timestamp,current_time,current_date,localtime,localtimestamp) in itsbare_functionsset, so the identity/schema ones were not recognised as functions in general expression positions.As a result, perfectly valid PostgreSQL was flagged as an unparsable section whenever one of these appeared as a function argument or in a multi-item select list:
while the parenthesised form parsed fine:
This change adds the missing niladic functions to the
postgresbare_functionsset so they parse correctly everywhere.Motivation / reference
The fix aligns the
postgresdialect with SQLFluff, which lists all of these in its postgresbare_functionsset:dialect_postgres.py—bare_functionsupdate: src/sqlfluff/dialects/dialect_postgres.pyPostgreSQL documentation confirms these have special syntactic status and are spelled without trailing parentheses:
— PostgreSQL: System Information Functions
Changes
crates/lib-dialects/src/postgres.rs— extend thepostgresbare_functionsset withCURRENT_CATALOG,CURRENT_ROLE,CURRENT_SCHEMA,CURRENT_USER,SESSION_USER,SYSTEM_USER, andUSER.crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/bare_functions.sql— extend the fixture to cover the newly supported functions (mirrors the equivalent SQLFluff fixture)..../postgres/sqlfluff/bare_functions.yml— regenerated expected parse tree; the new columns now parse asbare_function..../postgres/sqlfluff/alter_policy.ymland.../postgres/sqlfluff/create_policy.yml— regenerated. These existing fixtures usecurrent_userinside policyUSING (...)clauses; it was previously parsed ascolumn_reference → naked_identifierand is now correctly classified asbare_function. No SQL fixture input changed — only the expected trees, reflecting the improved parse.Testing
env UPDATE_EXPECT=1 cargo test -p sqruff-lib-dialects --test dialects.cargo test -p sqruff-lib-dialects --test dialects), including all postgres fixtures — no unparsable segments and no regressions (notably, addinguserdid not breakFROM user/user.colparses across the existing fixture corpus).SELECT f(current_schema, ...)andSELECT current_user, session_usernow lint without any unparsable-section findings.