Skip to content

Commit bccc50d

Browse files
author
Nathan Gabrielson
committed
checking for table relation respects temporary tables
1 parent b040612 commit bccc50d

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

core/relations.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,21 @@ func GetRelationType(ctx *sql.Context, schema string, relation string) (Relation
6060
// GetRelationTypeFromRoot performs the same function as GetRelationType, except that it uses the given root rather than
6161
// the working session's root.
6262
func GetRelationTypeFromRoot(ctx *sql.Context, schema string, relation string, root *RootValue) (RelationType, error) {
63-
// Check tables first
63+
// Check tables and temporary tables first
6464
ok, err := root.HasTable(ctx, doltdb.TableName{Schema: schema, Name: relation})
6565
if err != nil {
6666
return RelationType_DoesNotExist, err
6767
}
6868
if ok {
6969
return RelationType_Table, nil
7070
}
71+
72+
doltSession := dsess.DSessFromSess(ctx.Session)
73+
dbName := ctx.GetCurrentDatabase()
74+
if _, ok := doltSession.GetTemporaryTable(ctx, dbName, relation); ok {
75+
return RelationType_Table, nil
76+
}
77+
7178
// Check sequences next
7279
collection, err := sequences.LoadSequences(ctx, root)
7380
if err != nil {

testing/go/create_table_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,3 +450,21 @@ func TestCreateTableInherit(t *testing.T) {
450450
},
451451
})
452452
}
453+
454+
func TestCreateTemporaryTable(t *testing.T) {
455+
RunScripts(t, []ScriptTest{
456+
{
457+
Name: "Create temporary table with serial column",
458+
Assertions: []ScriptTestAssertion{
459+
{
460+
Query: "CREATE TEMP TABLE temp (id serial primary key)",
461+
Expected: []sql.Row{},
462+
},
463+
{
464+
Query: "CREATE TEMP TABLE temp2 (id serial)",
465+
Expected: []sql.Row{},
466+
},
467+
},
468+
},
469+
})
470+
}

0 commit comments

Comments
 (0)