Skip to content

Commit e698c0c

Browse files
authored
Merge pull request #21 from fmguerreiro/fix/postgres-unreserve-fulltext
fix(parser): guard MySQL FULLTEXT/SPATIAL table constraint on dialect
2 parents 9a1cd68 + da93efe commit e698c0c

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
[package]
1919
name = "pgmold-sqlparser"
2020
description = "Fork of sqlparser with additional PostgreSQL features (PARTITION OF, SECURITY DEFINER/INVOKER, SET params, EXCLUDE, TEXT SEARCH, AGGREGATE, FOREIGN TABLE/FDW, PUBLICATION, SUBSCRIPTION, ALTER DOMAIN/TRIGGER/EXTENSION, CAST, CONVERSION, LANGUAGE, RULE, STATISTICS, ACCESS METHOD, EVENT TRIGGER, TRANSFORM, SECURITY LABEL, USER MAPPING, TABLESPACE)"
21-
version = "0.60.12"
21+
version = "0.60.13"
2222
authors = ["Filipe Guerreiro <filipe.m.guerreiro@gmail.com>"]
2323
homepage = "https://github.com/fmguerreiro/datafusion-sqlparser-rs"
2424
documentation = "https://docs.rs/pgmold-sqlparser/"

src/parser/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10018,6 +10018,19 @@ impl<'a> Parser<'a> {
1001810018
None
1001910019
};
1002010020

10021+
// FULLTEXT and SPATIAL are MySQL-specific table constraint keywords. For
10022+
// dialects that don't support them (e.g. PostgreSQL) they are valid
10023+
// identifiers and must not be consumed here — the caller will parse them
10024+
// as column names instead.
10025+
if name.is_none()
10026+
&& self
10027+
.peek_one_of_keywords(&[Keyword::FULLTEXT, Keyword::SPATIAL])
10028+
.is_some()
10029+
&& !dialect_of!(self is GenericDialect | MySqlDialect)
10030+
{
10031+
return Ok(None);
10032+
}
10033+
1002110034
let next_token = self.next_token();
1002210035
match next_token.token {
1002310036
Token::Word(w) if w.keyword == Keyword::UNIQUE => {

tests/sqlparser_postgres.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7220,6 +7220,20 @@ fn parse_ts_datatypes() {
72207220
}
72217221
}
72227222

7223+
#[test]
7224+
fn parse_fulltext_column_and_index_in_postgres() {
7225+
match pg().verified_stmt("CREATE TABLE film (fulltext TSVECTOR NOT NULL)") {
7226+
Statement::CreateTable(CreateTable { columns, .. }) => {
7227+
assert_eq!(columns.len(), 1);
7228+
assert_eq!(columns[0].name.value, "fulltext");
7229+
assert_eq!(columns[0].data_type, DataType::TsVector);
7230+
}
7231+
_ => unreachable!(),
7232+
}
7233+
7234+
pg().verified_stmt("CREATE INDEX film_fulltext_idx ON film USING gist (fulltext)");
7235+
}
7236+
72237237
#[test]
72247238
fn parse_alter_table_constraint_not_valid() {
72257239
match pg_and_generic().verified_stmt(

0 commit comments

Comments
 (0)