Skip to content

feat: parse CREATE CAST, CREATE CONVERSION, CREATE LANGUAGE, CREATE RULE#2314

Closed
fmguerreiro wants to merge 43 commits intoapache:mainfrom
fmguerreiro:feat/catalog-small
Closed

feat: parse CREATE CAST, CREATE CONVERSION, CREATE LANGUAGE, CREATE RULE#2314
fmguerreiro wants to merge 43 commits intoapache:mainfrom
fmguerreiro:feat/catalog-small

Conversation

@fmguerreiro
Copy link
Copy Markdown
Contributor

Summary

Adds parser support for four PostgreSQL catalog DDL statements that currently fail to parse:

CREATE CAST (pgmold-89)

  • CREATE CAST (src AS dst) WITH FUNCTION func(arg_types) [AS ASSIGNMENT | AS IMPLICIT]
  • CREATE CAST (src AS dst) WITHOUT FUNCTION [AS ASSIGNMENT | AS IMPLICIT]
  • CREATE CAST (src AS dst) WITH INOUT [AS ASSIGNMENT | AS IMPLICIT]

CREATE CONVERSION (pgmold-91)

  • CREATE CONVERSION name FOR 'encoding' TO 'encoding' FROM function
  • CREATE DEFAULT CONVERSION name FOR 'encoding' TO 'encoding' FROM function

CREATE LANGUAGE (pgmold-92)

  • CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE name
  • Optional HANDLER func, INLINE func, VALIDATOR func clauses
  • NO VALIDATOR is handled (parsed as absent validator)

CREATE RULE (pgmold-93)

  • CREATE RULE name AS ON {SELECT|INSERT|UPDATE|DELETE} TO table [WHERE cond] DO {ALSO|INSTEAD} {NOTHING|stmt|(stmt; ...)}

Changes

  • src/keywords.rs: add ALSO, ASSIGNMENT, CONVERSION, IMPLICIT, INLINE, PROCEDURAL, TRUSTED
  • src/ast/ddl.rs: add CreateCast, CastFunctionKind, CastContext, CreateConversion, CreateLanguage, CreateRule, RuleEvent, RuleAction with Display and From impls
  • src/ast/mod.rs: re-export new types, add Statement variants and Display arms
  • src/ast/spans.rs: add Span::empty() arms for new variants
  • src/parser/mod.rs: dispatch in parse_create, add four parse functions
  • tests/sqlparser_postgres.rs: round-trip tests using pg().verified_stmt(sql) for all variants

Notes

Fork CI does not run automatically (known quirk); correctness is verified via inline tests. No Cargo.toml version bump — left at 0.60.9 per convention.

…R TABLE operations (#1)

PostgreSQL supports FORCE ROW LEVEL SECURITY and NO FORCE ROW LEVEL SECURITY
as ALTER TABLE operations. Add parsing support for both variants.
feat: parse EXCLUDE constraints for PostgreSQL
…m-main

# Conflicts:
#	Cargo.toml
#	src/ast/ddl.rs
#	src/ast/helpers/stmt_create_table.rs
#	src/ast/mod.rs
#	src/ast/spans.rs
#	src/ast/table_constraints.rs
#	src/parser/mod.rs
#	tests/sqlparser_postgres.rs
chore: merge upstream apache/datafusion-sqlparser-rs main
- Add HANDLER and VALIDATOR keywords to the keyword list
- Add FdwRoutineClause enum for HANDLER/NO HANDLER and VALIDATOR/NO VALIDATOR clauses
- Add CreateForeignDataWrapper struct for CREATE FOREIGN DATA WRAPPER
- Add CreateForeignTable struct for CREATE FOREIGN TABLE
- Export new types from ast::mod and add Statement variants
- Add spans.rs coverage returning Span::empty() for the new variants
- Dispatch on FOREIGN keyword in parse_create, branching on DATA WRAPPER or TABLE
- parse_create_foreign_data_wrapper: parses optional HANDLER/NO HANDLER,
  VALIDATOR/NO VALIDATOR, and OPTIONS clauses
- parse_create_foreign_table: parses IF NOT EXISTS, column list via parse_columns,
  required SERVER name, and optional OPTIONS clause
Round-trip tests via pg().verified_stmt for:
- FDW: name-only, HANDLER, NO HANDLER, NO VALIDATOR, combined HANDLER+VALIDATOR+OPTIONS
- FOREIGN TABLE: basic columns+SERVER, IF NOT EXISTS, table-level OPTIONS
Add Statement::CreateAggregate, CreateAggregate struct, CreateAggregateOption
enum, and AggregateModifyKind enum to represent PostgreSQL CREATE AGGREGATE
DDL. Options are stored as a typed enum covering all documented parameters
(SFUNC, STYPE, FINALFUNC, PARALLEL, moving-aggregate variants, etc.).
Wire AGGREGATE into the CREATE dispatch (before the or_replace error branch
so CREATE OR REPLACE AGGREGATE is accepted). parse_create_aggregate parses
the name, argument-type list, and the options block. Each recognised option
keyword dispatches to parse_create_aggregate_option which produces the typed
CreateAggregateOption variant.
Three tests covering: basic old-style aggregate (SFUNC/STYPE/FINALFUNC/INITCOND),
CREATE OR REPLACE with PARALLEL = SAFE, and moving-aggregate options
(MSFUNC/MINVFUNC/MSTYPE/MFINALFUNC_EXTRA/MFINALFUNC_MODIFY). All use
pg().verified_stmt() to assert parse-then-display round-trips identically.
feat: parse CREATE TEXT SEARCH CONFIGURATION/DICTIONARY/PARSER/TEMPLATE
# Conflicts:
#	src/ast/ddl.rs
#	src/ast/mod.rs
# Conflicts:
#	src/ast/ddl.rs
#	src/ast/mod.rs
#	src/parser/mod.rs
# Conflicts:
#	src/ast/ddl.rs
#	src/ast/mod.rs
#	tests/sqlparser_postgres.rs
feat: parse CREATE FOREIGN DATA WRAPPER and CREATE FOREIGN TABLE
PR #7 added the Statement::CreateAggregate variant but omitted the
corresponding match arm in the Spanned impl for Statement. Fork CI
never ran on the PR so this was not caught before merge.
fix(spans): add Span arm for CreateAggregate
Add PublicationTarget enum (AllTables, Tables, TablesInSchema),
CreatePublication struct, and CreateSubscription struct to ddl.rs.
Add Statement variants, Display arms, and re-exports in mod.rs.
Add Span::empty() arms in spans.rs.
Add PUBLICATION and SUBSCRIPTION to keywords.rs.
…rFunctionKind with Procedure, add SetTablespace to AlterTableOperation and AlterIndexOperation

Adds AST types and Display impls for:
- AlterDomain + AlterDomainOperation (ADD/DROP CONSTRAINT, RENAME, OWNER TO, SET SCHEMA/DEFAULT, DROP DEFAULT, VALIDATE CONSTRAINT)
- AlterTrigger + AlterTriggerOperation (RENAME TO)
- AlterExtension + AlterExtensionOperation (UPDATE TO, SET SCHEMA, OWNER TO, RENAME TO)
- AlterFunctionKind::Procedure variant for ALTER PROCEDURE
- AlterTableOperation::SetTablespace
- AlterIndexOperation::SetTablespace

Updates Spanned impls to remain exhaustive.
feat: parse CREATE PUBLICATION and CREATE SUBSCRIPTION
# Conflicts:
#	src/ast/ddl.rs
#	tests/sqlparser_postgres.rs
feat: parse ALTER TABLE/INDEX SET TABLESPACE, ALTER DOMAIN, ALTER TRIGGER, ALTER EXTENSION, ALTER PROCEDURE
…le AST nodes

Add AST structs and Display impls for four PostgreSQL catalog DDL
statements. Each follows the established fork pattern: struct in ddl.rs
with Debug/Clone/PartialEq/etc derives, Statement enum variant, Display
arm, From impl, and Span::empty() arm in spans.rs.

New keywords: ALSO, ASSIGNMENT, CONVERSION, IMPLICIT, INLINE,
PROCEDURAL, TRUSTED.

Closes pgmold-89, pgmold-91, pgmold-92, pgmold-93.
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.

1 participant