Skip to content

feat(postgres): add identity/schema niladic functions to bare_functions#2677

Open
skyf0l wants to merge 1 commit into
quarylabs:mainfrom
skyf0l:feat/postgres-bare-functions
Open

feat(postgres): add identity/schema niladic functions to bare_functions#2677
skyf0l wants to merge 1 commit into
quarylabs:mainfrom
skyf0l:feat/postgres-bare-functions

Conversation

@skyf0l
Copy link
Copy Markdown

@skyf0l skyf0l commented Jun 6, 2026

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, and user. sqruff's postgres dialect only registered the date/time niladic functions (current_timestamp, current_time, current_date, localtime, localtimestamp) in its bare_functions set, 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:

-- flagged "Unparsable section" before this change
SELECT some_function(current_schema, 'x');
SELECT current_user, session_user;

while the parenthesised form parsed fine:

SELECT current_schema();   -- ok (parsed as an ordinary function call)

This change adds the missing niladic functions to the postgres bare_functions set so they parse correctly everywhere.

Motivation / reference

The fix aligns the postgres dialect with SQLFluff, which lists all of these in its postgres bare_functions set:

PostgreSQL documentation confirms these have special syntactic status and are spelled without trailing parentheses:

current_catalog, current_role, current_schema, current_user, session_user, and user have special syntactic status in SQL: they must be called without trailing parentheses. (In PostgreSQL, parentheses can optionally be used with current_schema, but not with the others.)

PostgreSQL: System Information Functions

Changes

  • crates/lib-dialects/src/postgres.rs — extend the postgres bare_functions set with CURRENT_CATALOG, CURRENT_ROLE, CURRENT_SCHEMA, CURRENT_USER, SESSION_USER, SYSTEM_USER, and USER.
  • 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 as bare_function.
  • .../postgres/sqlfluff/alter_policy.yml and .../postgres/sqlfluff/create_policy.yml — regenerated. These existing fixtures use current_user inside policy USING (...) clauses; it was previously parsed as column_reference → naked_identifier and is now correctly classified as bare_function. No SQL fixture input changed — only the expected trees, reflecting the improved parse.

Testing

  • Regenerated fixtures with env UPDATE_EXPECT=1 cargo test -p sqruff-lib-dialects --test dialects.
  • Full dialect parse suite passes (cargo test -p sqruff-lib-dialects --test dialects), including all postgres fixtures — no unparsable segments and no regressions (notably, adding user did not break FROM user / user.col parses across the existing fixture corpus).
  • Verified end-to-end that previously-unparsable expressions such as SELECT f(current_schema, ...) and SELECT current_user, session_user now lint without any unparsable-section findings.

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.

1 participant