Skip to content

SQLite: Support multi-word type names - #2556

Open
LucaCappelletti94 wants to merge 7 commits into
apache:mainfrom
LucaCappelletti94:sqlite-multiword-type-names
Open

LucaCappelletti94 wants to merge 7 commits into
apache:mainfrom
LucaCappelletti94:sqlite-multiword-type-names

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Contributor

This PR lets SQLiteDialect parse type names made of several words or string literals in column definitions, CAST and ALTER TABLE ... ADD. Column constraints such as NOT NULL, PRIMARY KEY or DEFAULT still end the type name.

CREATE TABLE t (a UNSIGNED BIG INT, b NATIVE CHARACTER(70), c 'text');
SELECT CAST(a AS foo bar) FROM t;
-- Previously: Expected: ',' or ')' after column definition, found: BIG

SQLite accepts any sequence of names as a type, see datatypes.

@LucaCappelletti94 LucaCappelletti94 added enhancement New feature or request fuzzer A bug found by the fuzzer labels Sep 23, 2026
@LucaCappelletti94
LucaCappelletti94 marked this pull request as ready for review September 23, 2026 13:48
LucaCappelletti94 added a commit to LucaCappelletti94/sqlparser-rs that referenced this pull request Oct 1, 2026
@codecov-commenter

codecov-commenter commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.03%. Comparing base (594bb04) to head (68b01b4).

Files with missing lines Patch % Lines
src/parser/mod.rs 94.11% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2556      +/-   ##
==========================================
+ Coverage   81.99%   82.03%   +0.03%     
==========================================
  Files          42       42              
  Lines       35049    35129      +80     
  Branches    35049    35129      +80     
==========================================
+ Hits        28740    28817      +77     
- Misses       2744     2747       +3     
  Partials     3565     3565              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

LucaCappelletti94 added a commit to LucaCappelletti94/sqlparser-rs that referenced this pull request Oct 1, 2026
LucaCappelletti94 added a commit to LucaCappelletti94/sqlparser-rs that referenced this pull request Oct 2, 2026
LucaCappelletti94 added a commit to LucaCappelletti94/sqlparser-rs that referenced this pull request Oct 2, 2026
@LucaCappelletti94
LucaCappelletti94 force-pushed the sqlite-multiword-type-names branch 2 times, most recently from 295fab0 to d53faf5 Compare October 2, 2026 17:17
@LucaCappelletti94
LucaCappelletti94 force-pushed the sqlite-multiword-type-names branch from d53faf5 to b037052 Compare October 16, 2026 22:04

@sabir-akhadov-localstack sabir-akhadov-localstack left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Two non-blocking comments inline.

Comment thread src/parser/mod.rs
Ok(DataType::TsQuery)
}
_ => {
if self.dialect.supports_multiword_type_names() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Types with a dedicated arm never reach this path, so CREATE TABLE t (a INT FOO) and a TEXT FOO PRIMARY KEY still fail on SQLite while a FOO INT parses; sqlite 3.46 accepts both and stores the declared type as INT FOO. Rewinding to next_token_index and taking parse_multiword_type_name when the token after the dedicated arm would continue the name covers it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Built-in-prefixed type names are handled in 947dab70. The fallback covers both remaining name words and errors inside dedicated parsers, including ENUM FOO and TIMESTAMP WITH FOO.

Comment thread src/parser/mod.rs
),
_ => true, // e.g. comma immediately after column name
// A single-quoted string is a valid type name in SQLite's ids grammar.
Token::SingleQuotedString(_) => false,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

CREATE TABLE t (a NULL, b INT) is an untyped column with a NULL constraint in sqlite 3.46 (pragma_table_info type is empty) but parses here as Custom(NULL); Keyword::NULL is missing from this list although the continuation stop set in parse_multiword_type_name has it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Leading NULL is parsed as a constraint on an untyped column in 947dab70, and I added adequate tests for the rejected variants.

@LucaCappelletti94
LucaCappelletti94 force-pushed the sqlite-multiword-type-names branch 5 times, most recently from 947dab7 to d30b486 Compare October 24, 2026 13:35
@LucaCappelletti94
LucaCappelletti94 force-pushed the sqlite-multiword-type-names branch from d30b486 to 68b01b4 Compare October 24, 2026 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request fuzzer A bug found by the fuzzer SQLite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants