pingcap / parser

A MySQL Compatible SQL Parser
Apache License 2.0
1.41k stars 489 forks source link

The Collate in types.FieldType in ColumnDef seems to be always empty #1309

Open milkice233 opened 3 years ago

milkice233 commented 3 years ago

Feature Request

Is your feature request related to a problem? Please describe: When using pingcap/parser to parse SQL statement, the Collate in types.FieldType in ColumnDef seems to be always empty even if with collate specified in SQL statement.

Consider the following SQL statement: CREATE TABLE contacts (col1 char(10) CHARACTER SET ascii COLLATE ascii_bin, col2 varbinary(7), col3 varchar(20)); After parsing, the collate in types.FieldType in ColumnDef seems to be always empty and collate option can only be found in Options Array. image

Describe the feature you'd like: If a COLLATE of a column is found then set the COLLATE type to the collate in types.FieldType.

Describe alternatives you've considered: Users can always get the collate value in options array, but since there's a collate field in types.FieldType, I think the parser should take the responsibility of setting the collate option.

Teachability, Documentation, Adoption, Migration Strategy: I've initiated a pull request https://github.com/pingcap/parser/pull/1310