Skip to content

Commit 8c297bc

Browse files
Merge pull request #2349 from dolthub/nathan/tempTblRelation
Checking for table relation respects temporary tables
2 parents 9a3dec9 + bc647d2 commit 8c297bc

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

core/relations.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ func GetRelationType(ctx *sql.Context, schema string, relation string) (Relation
5454
if !ok {
5555
return RelationType_DoesNotExist, errors.Errorf("GetRelationType cannot find the database")
5656
}
57+
58+
// Verify relation against temporary tables created this session
59+
dbName := ctx.GetCurrentDatabase()
60+
if _, ok := session.GetTemporaryTable(ctx, dbName, relation); ok {
61+
return RelationType_Table, nil
62+
}
63+
5764
return GetRelationTypeFromRoot(ctx, schema, relation, state.WorkingRoot().(*RootValue))
5865
}
5966

@@ -68,6 +75,7 @@ func GetRelationTypeFromRoot(ctx *sql.Context, schema string, relation string, r
6875
if ok {
6976
return RelationType_Table, nil
7077
}
78+
7179
// Check sequences next
7280
collection, err := sequences.LoadSequences(ctx, root)
7381
if err != nil {

testing/go/create_table_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,15 @@ func TestCreateTable(t *testing.T) {
376376
},
377377
},
378378
},
379+
{
380+
Name: "create temporary table with serial column",
381+
Assertions: []ScriptTestAssertion{
382+
{
383+
Query: "CREATE TEMP TABLE temp (id serial primary key)",
384+
Expected: []sql.Row{},
385+
},
386+
},
387+
},
379388
})
380389
}
381390

0 commit comments

Comments
 (0)