Skip to content

Conversation

franloza
Copy link
Contributor

@franloza franloza commented Jul 10, 2025

Brief summary of the change made

Fixes #7000.

This PR implements support for PostgreSQL 16's IS JSON syntax validation as defined in the SQL/JSON standard. Previously, expressions like SELECT '{}' IS JSON; resulted in "Found unparsable section" errors.

Fixes the reported parsing issue where PostgreSQL IS JSON expressions were unparsable.

echo "SELECT '{}' IS JSON;" | sqlfluff lint --dialect postgres -


All Finished 📜 🎉!     

Are there any other side effects of this change that we should be aware of?

  • Although there are no breaking changes to existing functionality, this PR extends the IsClauseGrammar which could potentially affect other IS-clause parsing, but this is backwards compatible.

Pull Request checklist

  • Please confirm you have completed any of the necessary steps below.

  • Included test cases to demonstrate any code changes, which may be one or more of the following:

    • .yml rule test cases in test/fixtures/rules/std_rule_cases.
    • .sql/.yml parser test cases in test/fixtures/dialects (note YML files can be auto generated with tox -e generate-fixture-yml).
    • Full autofix test cases in test/fixtures/linter/autofix.
    • Other.
  • Added appropriate documentation for the change.

  • Created GitHub issues for any relevant followup/future enhancements if appropriate.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Added support for PostgreSQL 16's IS JSON syntax validation according to SQL/JSON standard, enabling parsing of expressions like SELECT '{}' IS JSON.

  • Added grammar rules in src/sqlfluff/dialects/dialect_postgres.py to support IS JSON clauses with type specifications (VALUE, SCALAR, ARRAY, OBJECT)
  • Added new non-reserved keywords 'KEYS' and 'SCALAR' in src/sqlfluff/dialects/dialect_postgres_keywords.py
  • Created comprehensive test suite in test/fixtures/dialects/postgres/is_json.sql and is_json.yml covering various JSON validation scenarios
  • Extended IsClauseGrammar while maintaining backward compatibility with existing IS clause parsing

4 files reviewed, 1 comment
Edit PR Review Bot Settings | Greptile

@@ -954,6 +954,7 @@ def get_keywords(keyword_list: list[tuple[str, str]], keyword_type: str) -> list
("INDEX_CLEANUP", "non-reserved"),
("IS_TEMPLATE", "non-reserved"),
("JSON", "non-reserved"),
("KEYS", "non-reserved"),
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider ordering keywords alphabetically within the list for consistency with surrounding entries

Copy link
Contributor

Coverage Results ✅

Name    Stmts   Miss  Cover   Missing
-------------------------------------
TOTAL   19870      0   100%

253 files skipped due to complete coverage.

Copy link
Contributor

@WittierDinosaur WittierDinosaur left a comment

Choose a reason for hiding this comment

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

LGTM

@WittierDinosaur WittierDinosaur added this pull request to the merge queue Jul 11, 2025
Merged via the queue into sqlfluff:main with commit 25ff42a Jul 11, 2025
28 checks passed
@franloza franloza deleted the postgres-is-json-syntax-support branch July 11, 2025 09:34
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.

Postgres unable to parse IS JSON expression
2 participants