Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

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 (generated from REL_19_STABLE @ b368bdd2301, post-beta 3, with the reverted beta features removed)
  • 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.0b4.post2

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.0b4.post2
File Size Uploaded Provenance Actions
tree_sitter_postgres-19.0.0b4.post2.tar.gz 6.1 MB With provenance Details for tree_sitter_postgres-19.0.0b4.post2.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for tree-sitter-postgres 19.0.0b4.post2
File Actions
tree_sitter_postgres-19.0.0b4.post2-cp39-abi3-win_arm64.whl CPython 3.9 abi3 Windows ARM64 Details for tree_sitter_postgres-19.0.0b4.post2-cp39-abi3-win_arm64.whl
tree_sitter_postgres-19.0.0b4.post2-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for tree_sitter_postgres-19.0.0b4.post2-cp39-abi3-win_amd64.whl
tree_sitter_postgres-19.0.0b4.post2-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.0b4.post2-cp39-abi3-musllinux_1_2_x86_64.whl
tree_sitter_postgres-19.0.0b4.post2-cp39-abi3-musllinux_1_2_aarch64.whl CPython 3.9 abi3 Linux musl 1.2+ ARM64 Details for tree_sitter_postgres-19.0.0b4.post2-cp39-abi3-musllinux_1_2_aarch64.whl
tree_sitter_postgres-19.0.0b4.post2-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.0b4.post2-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
tree_sitter_postgres-19.0.0b4.post2-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.0b4.post2-cp39-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
tree_sitter_postgres-19.0.0b4.post2-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for tree_sitter_postgres-19.0.0b4.post2-cp39-abi3-macosx_11_0_arm64.whl
tree_sitter_postgres-19.0.0b4.post2-cp39-abi3-macosx_10_9_x86_64.whl CPython 3.9 abi3 macOS 10.9+ x86-64 Details for tree_sitter_postgres-19.0.0b4.post2-cp39-abi3-macosx_10_9_x86_64.whl

Total release size: 12.9 MB

Release files / tree_sitter_postgres-19.0.0b4.post2.tar.gz

Download URL tree_sitter_postgres-19.0.0b4.post2.tar.gz
Size 6.1 MB
Tags Source
SHA-256 checksum
How to use checksums
f5907c99956622d3128b547c5c749deee0dce389fcba9b1904db80d72c32b3f0
BLAKE2b-256 checksum
How to use checksums
7515a77a172104364118458d6259d9d0723f5e000d9ce4010bee4ecb6e48c368
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.0b4.post2-cp39-abi3-win_arm64.whl

Download URL tree_sitter_postgres-19.0.0b4.post2-cp39-abi3-win_arm64.whl
Size 788.4 kB
Tags CPython 3.9 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
03fea83f7e6794f820ae11a34df44170562331d257c971d3f2a94052f71cc8ce
BLAKE2b-256 checksum
How to use checksums
d7d3ce3dac51d97ad45a61f06599382c3c2142161a4dce0056b23e9b82b6fc9d
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.0b4.post2-cp39-abi3-win_amd64.whl

Download URL tree_sitter_postgres-19.0.0b4.post2-cp39-abi3-win_amd64.whl
Size 786.7 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
3b22adfa3d71b1deac12126e86b635e076942d5924e1dcfa9a7f2186c69dc561
BLAKE2b-256 checksum
How to use checksums
89f1167c9047efabc98a183aaece0529bbbb0b56215e393319bd99c05e89a8a8
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.0b4.post2-cp39-abi3-musllinux_1_2_x86_64.whl

Download URL tree_sitter_postgres-19.0.0b4.post2-cp39-abi3-musllinux_1_2_x86_64.whl
Size 888.6 kB
Tags CPython 3.9 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
0e0a871344741f6194b87452d7ede00cb1bbea4c6dfd9405b4b4fdfab9a6e5e1
BLAKE2b-256 checksum
How to use checksums
f471a1a9cde587e8515a95ec120b1c8a4356dd0c33ebb87c9cb30fb18bf98df3
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.0b4.post2-cp39-abi3-musllinux_1_2_aarch64.whl

Download URL tree_sitter_postgres-19.0.0b4.post2-cp39-abi3-musllinux_1_2_aarch64.whl
Size 899.3 kB
Tags CPython 3.9 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
8c0cb94dea5d9a2dc696b3188db9cc56c34a30cbd813da0cf69eba9a86d0dac7
BLAKE2b-256 checksum
How to use checksums
2271b46575b4717df7d4da6eaa08d5a32e87021be372ade58ef8037a68289919
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.0b4.post2-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl

Download URL tree_sitter_postgres-19.0.0b4.post2-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Size 897.8 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
20f343f83615bf33277c73b0968ed9b4c4233722996247d88af6cc69b5d2ecaa
BLAKE2b-256 checksum
How to use checksums
7fbf182cd2ea80642dfeaafb92ca102feaf7404982d650619c769d8040af9290
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.0b4.post2-cp39-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl

Download URL tree_sitter_postgres-19.0.0b4.post2-cp39-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Size 889.3 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
6dbc572bd974aee501268f3817ca896801785b5d7ac3c417fab72ff102680460
BLAKE2b-256 checksum
How to use checksums
345cd17ddbc35cd02bd464f71cbbaede86e156dec1d225854981d7e148d978e4
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.0b4.post2-cp39-abi3-macosx_11_0_arm64.whl

Download URL tree_sitter_postgres-19.0.0b4.post2-cp39-abi3-macosx_11_0_arm64.whl
Size 907.7 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ec37edcea2f0b69f6fce3e1fb3fe1e2485431c14ab7c6b11209c517f56589ea0
BLAKE2b-256 checksum
How to use checksums
c24387fe2841bb7b2ff47fd646df4b9e832043e6fd0003a551c6e2b8b11879eb
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.0b4.post2-cp39-abi3-macosx_10_9_x86_64.whl

Download URL tree_sitter_postgres-19.0.0b4.post2-cp39-abi3-macosx_10_9_x86_64.whl
Size 794.1 kB
Tags CPython 3.9 abi3 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
04ae292d3d749d7ef5af499d6e39f9fe89390bd74eabcddc7af4bdfcaa488302
BLAKE2b-256 checksum
How to use checksums
3f6c220ec0514ed40796b8c293980fefe80641af6614944769e67689590b14c4
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.0b4.post2

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.0b4.post2.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