Skip to content

Conversation

@LucaCappelletti94
Copy link
Contributor

Adds full parsing for all PostgreSQL CREATE TYPE statement variants. Previously only composite and enum types were supported.

What's New

Range Types - Parse range type definitions with 6 configuration options

CREATE TYPE int4range AS RANGE (SUBTYPE = int4, CANONICAL = fn);

Base Types - Parse low-level type definitions with 19 options (INPUT/OUTPUT functions, ALIGNMENT, STORAGE, etc.)

CREATE TYPE complex (INPUT = in_fn, OUTPUT = out_fn, INTERNALLENGTH = 16);

Simple Declarations - Parse type shells without representation

CREATE TYPE typename;

The AST extends UserDefinedTypeRepresentation with three new variants (Range, SqlDefinition, None) and adds five supporting enums (UserDefinedTypeRangeOption, UserDefinedTypeSqlDefinitionOption, Alignment, UserDefinedTypeStorage, UserDefinedTypeInternalLength) with comprehensive rustdoc. The parser refactors parse_create_type() into modular functions (parse_create_type_composite(), parse_create_type_range(), and base type option parsers) that handle all PostgreSQL type configuration syntax. Tests provide comprehensive coverage with explicit AST verification for all variants and edge cases. Added 17 PostgreSQL-specific keywords, necessary to parse the keywords used in the type options (ALIGNMENT, CANONICAL, INTERNALLENGTH, PASSEDBYVALUE, RECEIVE, SEND, STORAGE, SUBTYPE, TYPMOD_IN, etc.).

Closes issue #2092

Copy link
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

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

Thanks @LucaCappelletti94! Changes look good to me overall, left some comments

Comment on lines 2013 to 2022
/// Range type: `CREATE TYPE name AS RANGE (options)`
Range {
options: Vec<UserDefinedTypeRangeOption>,
},
/// Base type (SQL definition): `CREATE TYPE name (options)`
///
/// Note the lack of `AS` keyword
SqlDefinition {
options: Vec<UserDefinedTypeSqlDefinitionOption>,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we include a link to the postgres docs for the new variants?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to, but they do not have a linkable subsection so the link would be to the same CREATE TYPE page. The sub-headers do not have the anchor link unfortunately.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah I think in that case linking to the postgres create type page for each variant would suffice, most important that its clear where each variant comes from especially if the overlying statement/enum is shared between multiple dialects. Basically similar to what the Enum { ... } variant above documents?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, doing that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

fn parse_range_option(&mut self) -> Result<UserDefinedTypeRangeOption, ParserError> {
let keyword = self.parse_one_of_keywords(&[
Keyword::SUBTYPE,
Keyword::SUBTYPE_OPCLASS,
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add tests for SUBTYPE_OPCLASS,SUBTYPE_DIFF and any other variants that are missing coverage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oke

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tentatively done, I think all are covered now.

LucaCappelletti94 and others added 6 commits November 12, 2025 11:16
Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
Copy link
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks @LucaCappelletti94!

@iffyio iffyio added this pull request to the merge queue Nov 13, 2025
Merged via the queue into apache:main with commit 78be8b1 Nov 13, 2025
10 checks passed
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.

2 participants