postgres

package module
v0.0.0-...-6f40dae Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package postgres parses PostgreSQL statements into github.com/aita/sqlkit/sql queries. It is the PostgreSQL frontend for github.com/aita/sqlkit/sqlparse, backed by the real PostgreSQL grammar (libpg_query): it parses and deparses through go-pgquery, which runs libpg_query as a WebAssembly module on the pure Go wazero runtime, and reuses the AST types from pg_query_go.

It lives in its own module so the parser dependency tree stays isolated from callers that only need the sqlparse abstraction or the sql package.

q, err := postgres.ParseOne("SELECT id FROM users WHERE active")
text, args, err := q.ToSQL(sql.PostgreSQLDialect{})

Limitations

See the github.com/aita/sqlkit/sqlparse package docs for the limitations common to every frontend (partial mapping with a deparsed RawSQL fallback, loss of comments and formatting on that fallback, and so on). Backend-specific notes:

  • Pure Go. go-pgquery compiles libpg_query to WebAssembly and runs it on the wazero runtime, so this module builds without cgo or a C toolchain (it still depends on pg_query_go for the AST types, whose cgo entry points are unused). WebAssembly execution is several times slower than calling libpg_query through cgo, which is acceptable for parsing/import workloads but not for parsing very high query volumes online.

  • Statement positions come from the parse result's statement locations, so each Query's position points at its start in the source text.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(text string) ([]sql.Query, error)

Parse parses one or more PostgreSQL statements using a default Parser.

func ParseOne

func ParseOne(text string) (sql.Query, error)

ParseOne parses exactly one PostgreSQL statement.

Types

type Parser

type Parser struct{}

Parser parses PostgreSQL SQL text into sqlkit/sql queries. The zero value is ready to use; it implements sqlparse.Parser.

func New

func New() Parser

New returns a PostgreSQL Parser.

func (Parser) Parse

func (Parser) Parse(text string) ([]sql.Query, error)

Parse parses one or more PostgreSQL statements in source order.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL