aiondb-pg-syntax

Pure SQL scanning and parsing helpers for PostgreSQL-compatible syntax. Every function here operates on &str (or parser tokens) and is free of engine, catalog, and storage coupling. The compatibility logic that builds on top lives in aiondb-pg-compat, which re-exports each module from here.

cargo

[dependencies]
aiondb-pg-syntax = { path = "../aiondb-pg-syntax" }

modules

modulepurpose
scanlow-level scanning primitives (trim_compat_statement, skip_sql_whitespace, consume_word_ci, parse_compat_identifier, parse_compat_uint, parse_compat_bool, ...).
do_scanscanning primitives for DO blocks and PL/pgSQL: dollar-quote handling and top-level keyword search.
do_parsersparsers for DO-block content (statement splitting, SELECT INTO targets, array-assign rewrite, record-field validation).
parsed_commandsparsers for PG-compatible DDL the native parser does not yet handle (ALTER INDEX, ALTER VIEW, ALTER TYPE ATTRIBUTE, CREATE/DROP CAST, ...).
prepareparsers for PREPARE, EXECUTE, and DEALLOCATE.
preparsebyte-level extractors run before the parser (dollar-quoted literals, CURRENT OF, CREATE SCHEMA AUTHORIZATION).
rule_parsersparsers and SQL reconstructors for CREATE RULE and DROP RULE.
type_refparsers for PG-compatible type references in routine and cast signatures.

key types

itemdescription
WITH_DML_RULE_ERROR_PREFIXtag prefix used by the WITH-DML rewrite to flag rewritten errors.
ParsedCompatTypeRefparsed type reference from a routine or cast signature.
ParsedCompatCast, ParsedCompatCastMethod, ParsedCompatDropCastparsed CREATE CAST / DROP CAST records.
ParsedCompatDropTypeOrDomain, ParsedCompatObjectName, ParsedCompatAlterRoleRenameparsed records for various DROP and ALTER ROLE ... RENAME variants.
ParsedCompatDropRoutine, CompatDropRoutineKindparsed DROP FUNCTION/PROCEDURE/ROUTINE.
CompatDeallocateTargetparsed DEALLOCATE target (named or ALL).

example

use aiondb_pg_syntax::scan::{parse_compat_identifier, trim_compat_statement};

assert_eq!(trim_compat_statement("SELECT 1;"), "SELECT 1");

let mut cursor = 0;
let ident = parse_compat_identifier("my_table rest", &mut cursor);
assert_eq!(ident.as_deref(), Some("my_table"));