@@ -2350,7 +2350,7 @@ type DropProtoBundle struct {
2350
2350
// {{.TableConstraints | sqlJoin ","}}{{if and .TableConstraints .Synonym}},{{end}}
2351
2351
// {{.Synonym | sqlJoin ","}}
2352
2352
// )
2353
- // PRIMARY KEY ({{.PrimaryKeys | sqlJoin ","}})
2353
+ // {{if .PrimaryKeys}} PRIMARY KEY ({{.PrimaryKeys | sqlJoin ","}}){{end}}
2354
2354
// {{.Cluster | sqlOpt}}
2355
2355
// {{.CreateRowDeletionPolicy | sqlOpt}}
2356
2356
//
@@ -2368,7 +2368,7 @@ type CreateTable struct {
2368
2368
Name * Path
2369
2369
Columns []* ColumnDef
2370
2370
TableConstraints []* TableConstraint
2371
- PrimaryKeys []* IndexKey
2371
+ PrimaryKeys []* IndexKey // when omitted, len(PrimaryKeys) = 0
2372
2372
Synonyms []* Synonym
2373
2373
Cluster * Cluster // optional
2374
2374
RowDeletionPolicy * CreateRowDeletionPolicy // optional
@@ -2438,22 +2438,26 @@ type BitReversedPositive struct {
2438
2438
BitReversedPositive token.Pos // position of "BIT_REVERSED_POSITIVE" keyword
2439
2439
}
2440
2440
2441
- // ColumnDef is column definition in CREATE TABLE.
2441
+ // ColumnDef is column definition in CREATE TABLE and ALTER TABLE ADD COLUMN.
2442
+ // Note: Some fields are not valid in ADD COLUMN.
2442
2443
//
2443
2444
// {{.Name | sql}}
2444
2445
// {{.Type | sql}} {{if .NotNull}}NOT NULL{{end}}
2445
2446
// {{.DefaultSemantics | sqlOpt}}
2446
2447
// {{if .Hidden.Invalid | not)}}HIDDEN{{end}}
2448
+ // {{if .PrimaryKey}}PRIMARY KEY{{end}}
2447
2449
// {{.Options | sqlOpt}}
2448
2450
type ColumnDef struct {
2449
2451
// pos = Name.pos
2450
- // end = Options.end || Hidden + 6 || DefaultSemantics.end || Null + 4 || Type.end
2452
+ // end = Options.end || Key + 3 || Hidden + 6 || DefaultSemantics.end || Null + 4 || Type.end
2451
2453
2452
2454
Null token.Pos // position of "NULL"
2455
+ Key token.Pos // position of "KEY" of PRIMARY KEY
2453
2456
2454
- Name * Ident
2455
- Type SchemaType
2456
- NotNull bool
2457
+ Name * Ident
2458
+ Type SchemaType
2459
+ NotNull bool
2460
+ PrimaryKey bool
2457
2461
2458
2462
DefaultSemantics ColumnDefaultSemantics // optional
2459
2463
0 commit comments