Skip to main content

tree-sitter-postgres

A tree-sitter grammar for PostgreSQL, generated directly from PostgreSQL's Bison grammar (gram.y) and keyword list (kwlist.h).

Features

  • Current as of PostgreSQL 19.0 (generated from REL_19_0)
  • 743 grammar rules covering the full PostgreSQL SQL syntax
  • 499 case-insensitive keywords across all four PG keyword categories
  • Correct operator precedence — 1 + 2 * 3 parses as 1 + (2 * 3)
  • PL/pgSQL support via a separate grammar with language injection
  • Generated, not hand-written — regenerate for any PostgreSQL version

Quick start

npm install
cd postgres && npx tree-sitter generate && npx tree-sitter test

Regenerating from PostgreSQL source

The grammar is generated from a local PostgreSQL checkout. Set PG_SOURCE_DIR to point at your PostgreSQL source tree:

export PG_SOURCE_DIR=/path/to/postgres

# Using just (recommended)
just generate

# Or run the script directly
node script/generate-grammar.js "$PG_SOURCE_DIR"
cd postgres && npx tree-sitter generate

Input files

File Source
src/backend/parser/gram.y Bison grammar (733 rules, 3236 alternatives)
src/include/parser/kwlist.h Keyword definitions (511 keywords)

Generator scripts

Script Purpose
script/generate-grammar.js Orchestrator — reads PG source, writes postgres/grammar.js
script/parse-gram-y.js Parses Bison grammar: rules, terminals, precedence, %prec annotations
script/parse-kwlist.js Parses keyword list into categories
script/codegen.js Generates tree-sitter grammar with precedence and optional-rule handling
postgres/harvest-conflicts.sh Iteratively discovers GLR conflicts needed by tree-sitter

Repository structure

postgres/               PostgreSQL SQL grammar
  grammar.js            Generated tree-sitter grammar
  src/                  Generated parser (C)
  test/corpus/          Test cases (35 tests)
  known-conflicts.json  GLR conflict pairs

plpgsql/                PL/pgSQL grammar
  grammar.js            Hand-written tree-sitter grammar
  src/scanner.c         External scanner for dollar-quoting and keywords
  test/corpus/          Test cases
  queries/              Highlights and injection queries

script/                 Shared generator code
  generate-grammar.js   SQL grammar orchestrator
  parse-gram-y.js       Bison parser
  parse-kwlist.js       Keyword parser
  codegen.js            Grammar code generator

bindings/               Language bindings (Node, Rust, Python, Go, Swift, C)

Design notes

Empty rule handling

Bison's /* EMPTY */ alternatives cannot be directly translated — tree-sitter forbids non-start rules that match the empty string. The generator propagates optionality upward via a fixpoint loop and wraps references with optional() at call sites.

Operator precedence

Binary operators are split into a separate a_expr_prec rule resolved by static precedence (no GLR), while complex patterns (IS, IN, BETWEEN, LIKE, subquery operators) stay in a_expr with GLR conflict resolution. Both prec.left/prec.right (generation-time) and prec.dynamic (runtime) are emitted.

PL/pgSQL

PL/pgSQL is implemented as a separate hand-written grammar in plpgsql/ with an external scanner for dollar-quoting and context-sensitive keywords. SQL expressions and statements within PL/pgSQL blocks are delegated to the postgres grammar via tree-sitter language injection (plpgsql/queries/injections.scm).

License

BSD 3-Clause

Metadata

Release files for tree-sitter-postgres 19.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tree-sitter-postgres 19.0.0
File Size Uploaded Provenance Actions
tree_sitter_postgres-19.0.0.tar.gz 6.1 MB With provenance Details for tree_sitter_postgres-19.0.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for tree-sitter-postgres 19.0.0
File Actions
tree_sitter_postgres-19.0.0-cp39-abi3-win_arm64.whl CPython 3.9 abi3 Windows ARM64 Details for tree_sitter_postgres-19.0.0-cp39-abi3-win_arm64.whl
tree_sitter_postgres-19.0.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for tree_sitter_postgres-19.0.0-cp39-abi3-win_amd64.whl
tree_sitter_postgres-19.0.0-cp39-abi3-musllinux_1_2_x86_64.whl CPython 3.9 abi3 Linux musl 1.2+ x86-64 Details for tree_sitter_postgres-19.0.0-cp39-abi3-musllinux_1_2_x86_64.whl
tree_sitter_postgres-19.0.0-cp39-abi3-musllinux_1_2_aarch64.whl CPython 3.9 abi3 Linux musl 1.2+ ARM64 Details for tree_sitter_postgres-19.0.0-cp39-abi3-musllinux_1_2_aarch64.whl
tree_sitter_postgres-19.0.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl CPython 3.9 abi3 Linux glibc 2.28+ ARM64, Linux glibc 2.17+ ARM64 Details for tree_sitter_postgres-19.0.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
tree_sitter_postgres-19.0.0-cp39-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl CPython 3.9 abi3 Linux glibc 2.5+ x86-64, Linux glibc 2.28+ x86-64 Details for tree_sitter_postgres-19.0.0-cp39-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
tree_sitter_postgres-19.0.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for tree_sitter_postgres-19.0.0-cp39-abi3-macosx_11_0_arm64.whl
tree_sitter_postgres-19.0.0-cp39-abi3-macosx_10_9_x86_64.whl CPython 3.9 abi3 macOS 10.9+ x86-64 Details for tree_sitter_postgres-19.0.0-cp39-abi3-macosx_10_9_x86_64.whl

Total release size: 12.9 MB

Release files / tree_sitter_postgres-19.0.0.tar.gz

Download URL tree_sitter_postgres-19.0.0.tar.gz
Size 6.1 MB
Tags Source
SHA-256 checksum
How to use checksums
ea295ba0e26cbdb2f08afc420cb6cbfc4cf35b07e5c1d92baac78f1d15f56495
BLAKE2b-256 checksum
How to use checksums
b67d631998c1bd29b1594364d8ec69e8b2671e5464991b29705bbb7d7f17f7be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / tree_sitter_postgres-19.0.0-cp39-abi3-win_arm64.whl

Download URL tree_sitter_postgres-19.0.0-cp39-abi3-win_arm64.whl
Size 788.2 kB
Tags CPython 3.9 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
6171cadf25543617a7812bfb77a2c1c19507794c775aa804e00c435bacab0efe
BLAKE2b-256 checksum
How to use checksums
4da2793cd75b22e20b5f5ed1ffb68507950c123dafad43bfe03e0701c51627da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / tree_sitter_postgres-19.0.0-cp39-abi3-win_amd64.whl

Download URL tree_sitter_postgres-19.0.0-cp39-abi3-win_amd64.whl
Size 786.5 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
e67eebab58c87108e6f3e7c7c4c3660c1b5c4cb6811a5b27d2d3929cade16760
BLAKE2b-256 checksum
How to use checksums
a8c40e054c03d31654dea1edaf056106a2fc113dff791c9dbfde417107668621
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / tree_sitter_postgres-19.0.0-cp39-abi3-musllinux_1_2_x86_64.whl

Download URL tree_sitter_postgres-19.0.0-cp39-abi3-musllinux_1_2_x86_64.whl
Size 888.4 kB
Tags CPython 3.9 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
c0f2bc64dc519423d08af12355bd605885b18d45c37e1a64cc2128eff43112a1
BLAKE2b-256 checksum
How to use checksums
be95606be2b04c024b41d23bfa5a2fb9120400248a802aad30b7a8cdd87d0c00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / tree_sitter_postgres-19.0.0-cp39-abi3-musllinux_1_2_aarch64.whl

Download URL tree_sitter_postgres-19.0.0-cp39-abi3-musllinux_1_2_aarch64.whl
Size 899.2 kB
Tags CPython 3.9 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
4fc1a133d785395e7b2cb40c5e18d9586061dea202906eb6f9cc60074b5a5d41
BLAKE2b-256 checksum
How to use checksums
3b3c072704ce2108d654c503642d1490e4ffc59b34e65af7981803db0c98e2d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / tree_sitter_postgres-19.0.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl

Download URL tree_sitter_postgres-19.0.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Size 897.7 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
b4d63ce4cf822d6751e11be39601067eb398352b1313270c63a0c09c2ab399b4
BLAKE2b-256 checksum
How to use checksums
deaad566a1697016eaa83d120b12d60b78ccae6846661e2629a0f7c8d552bb7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / tree_sitter_postgres-19.0.0-cp39-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl

Download URL tree_sitter_postgres-19.0.0-cp39-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Size 889.1 kB
Tags CPython 3.9 Linux glibc 2.28+ x86-64 Linux glibc 2.5+ x86-64 abi3
SHA-256 checksum
How to use checksums
d6e85da09f9d31dcb749c9937cf6975e00918e48e2f0bc0882fb3eec1831f575
BLAKE2b-256 checksum
How to use checksums
5584dd9de0f62c2054c2fde5f7e8343fd5debad9130961fe14b7f088ee48d801
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / tree_sitter_postgres-19.0.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL tree_sitter_postgres-19.0.0-cp39-abi3-macosx_11_0_arm64.whl
Size 907.5 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
4aef9e5bf44a55702a182357b8894b39db0438a3e6641eb20e253d75c8413eab
BLAKE2b-256 checksum
How to use checksums
50beca8cd94f77c43734affb05cc98a8f1f2b054acbf9a8b53e776e1c6267fe1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / tree_sitter_postgres-19.0.0-cp39-abi3-macosx_10_9_x86_64.whl

Download URL tree_sitter_postgres-19.0.0-cp39-abi3-macosx_10_9_x86_64.whl
Size 794.0 kB
Tags CPython 3.9 abi3 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
749cab1c0e81e889b5fa4e6636de04622744b226af33a7d57053b26b8351dd93
BLAKE2b-256 checksum
How to use checksums
ab439b2b99cf17935e84bf6ec45b71ea3523fbec19557c557b393b63d419301c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Security for tree-sitter-postgres 19.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 9 files in this release have been uploaded with provenance metadata.

Select from 9 files

Attestation for tree_sitter_postgres-19.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page