Skip to content

Commit fa72192

Browse files
committed
Fixed PK NN behavior to match MySQL
Signed-off-by: Daylon Wilkins <[email protected]>
1 parent 62780e1 commit fa72192

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

engine_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2515,6 +2515,27 @@ func TestCreateTable(t *testing.T) {
25152515
}
25162516

25172517
require.Equal(s, testTable.Schema())
2518+
2519+
testQuery(t, e,
2520+
"CREATE TABLE t4(a INTEGER,"+
2521+
"b TEXT NOT NULL,"+
2522+
"c bool, primary key (a))",
2523+
[]sql.Row(nil),
2524+
)
2525+
2526+
db, err = e.Catalog.Database("mydb")
2527+
require.NoError(err)
2528+
2529+
testTable, ok = db.Tables()["t4"]
2530+
require.True(ok)
2531+
2532+
s = sql.Schema{
2533+
{Name: "a", Type: sql.Int32, Nullable: false, PrimaryKey: true, Source: "t4"},
2534+
{Name: "b", Type: sql.Text, Nullable: false, PrimaryKey: false, Source: "t4"},
2535+
{Name: "c", Type: sql.Uint8, Nullable: true, Source: "t4"},
2536+
}
2537+
2538+
require.Equal(s, testTable.Schema())
25182539
}
25192540

25202541
func TestDropTable(t *testing.T) {

sql/parse/parse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ func getColumn(cd *sqlparser.ColumnDefinition, indexes []*sqlparser.IndexDefinit
545545
}
546546

547547
return &sql.Column{
548-
Nullable: !bool(typ.NotNull),
548+
Nullable: !isPkey && !bool(typ.NotNull),
549549
Type: internalTyp,
550550
Name: cd.Name.String(),
551551
PrimaryKey: isPkey,

sql/parse/parse_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ var fixtures = map[string]sql.Node{
7272
sql.Schema{{
7373
Name: "a",
7474
Type: sql.Int32,
75-
Nullable: true,
75+
Nullable: false,
7676
PrimaryKey: true,
7777
}, {
7878
Name: "b",
@@ -87,12 +87,12 @@ var fixtures = map[string]sql.Node{
8787
sql.Schema{{
8888
Name: "a",
8989
Type: sql.Int32,
90-
Nullable: true,
90+
Nullable: false,
9191
PrimaryKey: true,
9292
}, {
9393
Name: "b",
9494
Type: sql.Text,
95-
Nullable: true,
95+
Nullable: false,
9696
PrimaryKey: true,
9797
}},
9898
),

0 commit comments

Comments
 (0)