Skip to content

Add schema support to postgis#19

Merged
antialize merged 17 commits intomainfrom
postgres_schema
May 3, 2026
Merged

Add schema support to postgis#19
antialize merged 17 commits intomainfrom
postgres_schema

Conversation

@antialize
Copy link
Copy Markdown
Owner

Fixes #14

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds PostgreSQL/PostGIS schema-qualified name support across schema parsing and type-checking so statements like CREATE SCHEMA ... and schema.table references can be represented and resolved (with a default public search path).

Changes:

  • Introduces QualifiedIdentifier keys and lookup_name helpers to resolve qualified/unqualified names with a PostgreSQL search path.
  • Extends schema parsing/evaluation to understand CREATE SCHEMA, DROP SCHEMA (via DropDatabase), SET search_path, and sequences (CREATE/DROP SEQUENCE, nextval()).
  • Updates parsing structures for qualified references (e.g., REFERENCES schema.table) and adds tests + updated golden JSON fixtures.

Reviewed changes

Copilot reviewed 24 out of 26 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
type-test/src/main.rs Formats table names as schema.table when schema-qualified.
type-test/postgresql3.sql Adds a richer PostgreSQL schema fixture exercising schemas, functions, sequences.
type-test/postgresql3.json Adds expected output for the new PostgreSQL schema fixture.
type-test/postgresql1.json Updates expected table names to include public. prefix.
type-test/postgresql2.json Updates expected table names to include public. prefix.
qusql-type/src/typer.rs Adds qualified-name key conversion + search-path-based schema lookup.
qusql-type/src/type_truncate.rs Updates TRUNCATE typing to use qualified lookups.
qusql-type/src/type_set.rs Updates SET typing for new AST shape (multiple expressions).
qusql-type/src/type_reference.rs Updates table reference typing to support schema-qualified tables.
qusql-type/src/type_lock.rs Updates LOCK typing to use qualified lookups.
qusql-type/src/type_insert_replace.rs Updates INSERT/REPLACE typing to use search-path-aware qualified lookup.
qusql-type/src/type_function.rs Resolves user-defined functions using qualified keys + search path.
qusql-type/src/type_expression.rs Passes search-path parameter through to parse_column call sites.
qusql-type/src/type_delete.rs Updates DELETE typing to use qualified table lookup.
qusql-type/src/type_call.rs Updates CALL typing to use qualified lookup + search path.
qusql-type/src/schema.rs Implements schema/sequence/search_path tracking and qualified-name map keys.
qusql-type/src/lib.rs Adds tests for PostgreSQL schema support + MySQL rejection behavior.
qusql-parse/src/visit.rs Walks all SET expressions (now a vector).
qusql-parse/src/statement.rs Extends SET parsing to support LOCAL/SESSION and TO with multi-values.
qusql-parse/src/identifier.rs Changes identifier ordering/equality behavior.
qusql-parse/src/data_type.rs Allows schema-qualified table in REFERENCES (data type property).
qusql-parse/src/create_table.rs Allows schema-qualified table in foreign key REFERENCES.
qusql-parse/src/create_function.rs Parses function names as qualified names (PostgreSQL schema support).
qusql-parse/src/alter_table.rs Allows schema-qualified table in ALTER TABLE ... REFERENCES.
parse-test/mysql-tests.json Updates expected issue serialization / AST output for parser changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread qusql-parse/src/identifier.rs
Comment thread qusql-type/src/schema.rs
Comment thread qusql-type/src/schema.rs
Comment thread qusql-type/src/schema.rs Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds PostgreSQL schema (namespace) support across parsing, schema ingestion, and query typing to address issue #14 (“Support postgres schemas”), including handling CREATE SCHEMA, schema-qualified object names, and PostgreSQL search_path-style resolution.

Changes:

  • Introduces schema-aware identifiers (QualifiedIdentifier) and map lookup helpers with PostgreSQL search_path fallback.
  • Extends schema parsing/evaluation to handle CREATE SCHEMA, DROP SCHEMA, CREATE/DROP SEQUENCE, and PostgreSQL SET [LOCAL|SESSION] search_path TO ....
  • Updates typing logic and test fixtures to use qualified names (e.g. public.table) and adds coverage for PostgreSQL vs MySQL behavior.

Reviewed changes

Copilot reviewed 24 out of 26 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
type-test/src/main.rs Formats schema/table names from QualifiedIdentifier when emitting JSON.
type-test/postgresql3.sql Adds a PostgreSQL schema-heavy fixture (schemas, search_path, sequences).
type-test/postgresql3.json Expected output for the new PostgreSQL schema fixture.
type-test/postgresql2.json Updates expected table names to include public. prefix.
type-test/postgresql1.json Updates expected table names to include public. prefix.
qusql-type/src/typer.rs Adds qualified-name key conversion + search_path + schema lookup via lookup_name.
qusql-type/src/type_truncate.rs Uses qualified-name lookup for TRUNCATE table validation.
qusql-type/src/type_set.rs Adapts to SET now carrying multiple expressions per variable.
qusql-type/src/type_reference.rs Resolves schema-qualified table references and adjusts index-key construction.
qusql-type/src/type_lock.rs Uses qualified-name lookup for LOCK table validation.
qusql-type/src/type_insert_replace.rs Switches INSERT table lookup to schema-aware lookup_name + search_path.
qusql-type/src/type_function.rs Looks up functions using qualified identifiers + search_path; passes search_path into type parsing.
qusql-type/src/type_expression.rs Updates parse_column call sites for new search_path parameter.
qusql-type/src/type_delete.rs Uses qualified-name lookup for DELETE target tables.
qusql-type/src/type_call.rs Looks up procedures using qualified identifiers + search_path; passes search_path into type parsing.
qusql-type/src/schema.rs Core schema support: qualified keys, lookup helpers, search_path tracking, schema/sequence handling, schema-qualified FROM handling.
qusql-type/src/lib.rs Adds unit tests for PostgreSQL schema support and MySQL CREATE SCHEMA failure cases.
qusql-parse/src/visit.rs Updates statement walker for SET now containing multiple expressions per variable.
qusql-parse/src/statement.rs Extends SET AST to include LOCAL/SESSION modifiers and multiple expressions per variable; parses TO syntax.
qusql-parse/src/identifier.rs Changes Identifier ordering/equality semantics (now ASCII case-insensitive).
qusql-parse/src/data_type.rs Allows schema-qualified names in REFERENCES inside column data types.
qusql-parse/src/create_table.rs Allows schema-qualified names in REFERENCES for FK definitions.
qusql-parse/src/create_function.rs Allows schema-qualified function names in CREATE FUNCTION.
qusql-parse/src/alter_table.rs Allows schema-qualified names in REFERENCES for ALTER TABLE FK additions.
parse-test/mysql-tests.json Updates expected parse-test output for modified Issue shape and SET AST shape.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread qusql-type/src/schema.rs Outdated
Comment thread qusql-type/src/schema.rs Outdated
Comment thread qusql-type/src/schema.rs
Comment thread type-test/postgresql3.sql Outdated
Comment thread qusql-parse/src/identifier.rs
@antialize antialize force-pushed the postgres_schema branch 2 times, most recently from 4cdb5fb to 4a0c55b Compare April 30, 2026 19:04
antialize added 3 commits May 2, 2026 20:41
SQL identifiers are case-insensitive (ANSI SQL, PostgreSQL, MySQL). Make
Identifier's Eq, PartialEq, Ord and PartialOrd use ASCII-case-insensitive
comparison via a new ord_ignore_ascii_case helper.

Remove the Borrow<str> impl which would violate the contract: Borrow requires
that the hashed/ordered borrowed form equals the owned form, but str comparison
is case-sensitive while Identifier comparison is now case-insensitive.
Change the 'references_table' field in AddForeignKey, the inline
CreateDefinition::ForeignKeyDefinition, and DataTypeProperty::References
from Identifier to QualifiedName.  This allows writing e.g.

  id integer REFERENCES books.authors(id)

without a syntax error in the parser.
PostgreSQL allows schema-qualified function names in CREATE FUNCTION, e.g.
  CREATE FUNCTION myschema.myfunc(...) ...

Change CreateFunction::name from Identifier to QualifiedName to support this.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 26 out of 28 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread qusql-type/src/schema.rs Outdated
Comment thread qusql-type/src/schema.rs
Comment thread qusql-type/src/type_function.rs Outdated
Comment thread qusql-parse/src/identifier.rs
Comment thread qusql-parse/src/statement.rs Outdated
Comment thread qusql-parse/src/statement.rs
antialize added 14 commits May 3, 2026 09:15
…upport

PostgreSQL uses:  SET LOCAL search_path TO schema1, schema2;
                  SET SESSION search_path TO schema1, schema2;

Add local_span and session_span fields to Set.
Change values from Vec<(SetVariable, Expression)> to
Vec<(SetVariable, Vec<Expression>)> so comma-separated value lists
parse correctly.
- visit.rs: handle new QualifiedName fields in CreateFunction, REFERENCES,
  and Set (multi-value Vec<Expression>)
- parse-test snapshots: regenerated to reflect updated AST shapes
- qname_to_key: converts a parsed QualifiedName to a QualifiedIdentifier
  keeping unqualified names as Unqualified (so lookup_name can resolve them
  via the search path rather than hardcoding 'public')
- search_path: returns ['public'] for PostgreSQL, [] for other dialects
- get_schema_by_key: CTE check + lookup_name with search_path

Remove the old get_schema and table_key methods which pre-qualified unqualified
names with 'public' and then called lookup_name with an empty search path,
which was incorrect.
Replace the old resolve_table_name + direct schemas.schemas.get() pattern
with qname_to_key (keeps unqualified names Unqualified) + get_schema_by_key
(resolves via search_path) in:

- type_delete.rs
- type_lock.rs
- type_truncate.rs
- type_reference.rs
- type_set.rs: update for Set.values now being Vec<(SetVariable, Vec<Expression>)>
…okups, thread search_path into parse_column

- type_call.rs: qname_to_key + lookup_name(procedures, search_path); pass
  search_path to parse_column for procedure parameter types
- type_insert_replace.rs: qname_to_key + lookup_name(schemas, search_path)
- type_function.rs: Function::Other uses Unqualified/Qualified key +
  typer.search_path() instead of table_key + empty search path; pass
  search_path to parse_column for return type
- type_expression.rs: pass &[] to parse_column for CAST/CONVERT/TypeCast
  (no type map available there)
…are lookup helpers

- Change schemas, procedures, functions, types maps from Identifier-keyed
  to QualifiedIdentifier-keyed (Qualified for PostgreSQL, Unqualified for MySQL)
- Add schema field to IndexKey for PostgreSQL schema-qualified index tracking
- Add lookup_name_key, lookup_name_mut helpers alongside existing lookup_name
- Make lookup_name search-path-aware (tries qualified keys from search_path
  when given an unqualified name)
- Add parse_qname / parse_qname_for_lookup on SchemaCtx for QualifiedName -> QualifiedIdentifier conversion
- Resolve Named types (enums) via schema-qualified lookup with search_path fallback
- lib.rs: postgres_schema_support test covering CREATE SCHEMA, qualified
  table CREATE/SELECT/INSERT, DROP SCHEMA cascade, search_path via SET,
  CREATE SEQUENCE, nextval, CREATE TYPE AS ENUM, qualified enum usage
- type-test/postgresql1.json, postgresql2.json: update 'public.' prefix for
  tables now stored as Qualified('public', name)
- type-test/postgresql3.sql + postgresql3.json: multi-schema library
  catalog schema using apply_revision migration function pattern
…entifier

- Add SearchPath<'a>: Copy trait with impls for &[&str], &[Identifier], and ()
  so lookup helpers no longer require Vec<&str> allocations at each call site
- Remove search_path_strs(); callers pass self.search_path.as_slice() directly
- Make lookup_name{,_key,_mut}, type_kind_from_parse, parse_column, and
  process_alter_specification generic over S: SearchPath<'a>
- Change rows map key from &'a str to QualifiedIdentifier<'a> so schema-qualified
  and unqualified tables with the same bare name are tracked independently
- Update process_insert/delete/update/truncate/rename_table to use qualified keys
- Refactor resolve_from_rows to use lookup_name_key so the search-path walk
  happens once; use the resolved key directly for the rows lookup
- Add Display for QualifiedIdentifier (Unqualified -> "name", Qualified -> "schema.name")
- Remove unqualified_name() helper from typer.rs (no longer needed)
@antialize antialize merged commit c6af404 into main May 3, 2026
7 checks passed
@antialize antialize deleted the postgres_schema branch May 3, 2026 07:19
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.

Support postgres schemas

2 participants