Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9810,6 +9810,18 @@ impl<'a> Parser<'a> {
None
};

// Peek instead of consuming: FULLTEXT/SPATIAL are only table constraints in
// MySQL/Generic, so consuming them before confirming the dialect would break
// the column-name fallback in other dialects (e.g. PostgreSQL).
if name.is_none()
&& self
.peek_one_of_keywords(&[Keyword::FULLTEXT, Keyword::SPATIAL])
.is_some()
&& !dialect_of!(self is GenericDialect | MySqlDialect)
{
return Ok(None);
}

let next_token = self.next_token();
match next_token.token {
Token::Word(w) if w.keyword == Keyword::UNIQUE => {
Expand Down
26 changes: 26 additions & 0 deletions tests/sqlparser_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7107,6 +7107,32 @@ fn parse_alter_table_replica_identity() {
}
}

#[test]
fn parse_fulltext_as_column_name() {
match pg().verified_stmt("CREATE TABLE film (fulltext TSVECTOR NOT NULL)") {
Statement::CreateTable(CreateTable { columns, .. }) => {
assert_eq!(
columns,
vec![ColumnDef {
name: "fulltext".into(),
data_type: DataType::TsVector,
options: vec![ColumnOptionDef {
name: None,
option: ColumnOption::NotNull,
}],
}]
);
}
_ => unreachable!(),
}

pg().verified_stmt("CREATE TABLE geo (spatial TEXT NOT NULL)");

pg().verified_stmt("CREATE INDEX film_fulltext_idx ON film USING GIST (fulltext)");

pg().verified_stmt("CREATE INDEX geo_spatial_idx ON geo USING GIST (spatial)");
}

#[test]
fn parse_ts_datatypes() {
match pg_and_generic().verified_stmt("CREATE TABLE foo (x TSVECTOR)") {
Expand Down
Loading