@@ -16598,3 +16598,60 @@ fn parse_create_view_if_not_exists() {
1659816598 res.unwrap_err()
1659916599 );
1660016600}
16601+
16602+ #[test]
16603+ fn test_parse_not_null_in_column_options() {
16604+ let canonical = concat!(
16605+ "CREATE TABLE foo (",
16606+ "abc INT DEFAULT (42 IS NOT NULL) NOT NULL,",
16607+ " def INT,",
16608+ " def_null BOOL GENERATED ALWAYS AS (def IS NOT NULL) STORED,",
16609+ " CHECK (abc IS NOT NULL)",
16610+ ")"
16611+ );
16612+ all_dialects().verified_stmt(canonical);
16613+ all_dialects().one_statement_parses_to(
16614+ concat!(
16615+ "CREATE TABLE foo (",
16616+ "abc INT DEFAULT (42 NOT NULL) NOT NULL,",
16617+ " def INT,",
16618+ " def_null BOOL GENERATED ALWAYS AS (def NOT NULL) STORED,",
16619+ " CHECK (abc NOT NULL)",
16620+ ")"
16621+ ),
16622+ canonical,
16623+ );
16624+ }
16625+
16626+ #[test]
16627+ fn test_parse_default_with_collate_column_option() {
16628+ let sql = "CREATE TABLE foo (abc TEXT DEFAULT 'foo' COLLATE 'en_US')";
16629+ let stmt = all_dialects().verified_stmt(sql);
16630+ if let Statement::CreateTable(CreateTable { mut columns, .. }) = stmt {
16631+ let mut column = columns.pop().unwrap();
16632+ assert_eq!(&column.name.value, "abc");
16633+ assert_eq!(column.data_type, DataType::Text);
16634+ let collate_option = column.options.pop().unwrap();
16635+ if let ColumnOptionDef {
16636+ name: None,
16637+ option: ColumnOption::Collation(collate),
16638+ } = collate_option
16639+ {
16640+ assert_eq!(collate.to_string(), "'en_US'");
16641+ } else {
16642+ panic!("Expected collate column option, got {collate_option}");
16643+ }
16644+ let default_option = column.options.pop().unwrap();
16645+ if let ColumnOptionDef {
16646+ name: None,
16647+ option: ColumnOption::Default(Expr::Value(value)),
16648+ } = default_option
16649+ {
16650+ assert_eq!(value.to_string(), "'foo'");
16651+ } else {
16652+ panic!("Expected default column option, got {default_option}");
16653+ }
16654+ } else {
16655+ panic!("Expected create table statement");
16656+ }
16657+ }
0 commit comments