taozhi8833998 / node-sql-parser

Parse simple SQL statements into an abstract syntax tree (AST) with the visited tableList and convert it back to SQL
https://taozhi8833998.github.io/node-sql-parser/
Apache License 2.0
818 stars 181 forks source link

`create table` for mysql - places `NOT NULL` in invalid position for generated column #2196

Closed croconut closed 2 weeks ago

croconut commented 3 weeks ago

Describe the bug

My table with column which has a int(11) generated (generation expression) virtual not null definition is getting sqlify'd to have the not null after int(11) instead of after the generated (generation expression) virtual/stored part, which is invalid in mysql.

Database Engine mysql

To Reproduce

let table = `
create table \`d\`
(
    \`id\` int (11) primary key auto_increment not null,
    \`d_name\` varchar(15) not null,
    \`d_id\` int(11) generated always as (cast(trim(d_name) as signed) ) virtual not null
);
`;
let ast = parser.astify(table)
// removed FKs from table's AST
// ...
return parser.sqlify(ast)
// returns column as `d_id` int(11) not null generated (...) virtual

-the node-sql-parser version: 5.3.3 -the node version: 20.15.1