diff --git a/server/ast/select.go b/server/ast/select.go index a688a7bb64..fe71bce077 100644 --- a/server/ast/select.go +++ b/server/ast/select.go @@ -110,11 +110,11 @@ func nodeSelectExpr(ctx *Context, node tree.SelectExpr) (vitess.SelectExpr, erro case tree.UnqualifiedStar: return &vitess.StarExpr{}, nil case *tree.UnresolvedName: - if expr.NumParts > 2 { - return nil, errors.Errorf("referencing items outside the schema or database is not yet supported") - } if expr.Star { var tableName vitess.TableName + if expr.NumParts > 2 { + tableName.SchemaQualifier = vitess.NewTableIdent(expr.Parts[2]) + } if expr.NumParts == 2 { tableName.Name = vitess.NewTableIdent(expr.Parts[1]) } @@ -123,6 +123,9 @@ func nodeSelectExpr(ctx *Context, node tree.SelectExpr) (vitess.SelectExpr, erro }, nil } else { var tableName vitess.TableName + if expr.NumParts > 2 { + tableName.SchemaQualifier = vitess.NewTableIdent(expr.Parts[2]) + } if expr.NumParts == 2 { tableName.Name = vitess.NewTableIdent(expr.Parts[1]) } diff --git a/testing/go/dolt_tables_test.go b/testing/go/dolt_tables_test.go index 10ad79d3d7..3288c15d31 100755 --- a/testing/go/dolt_tables_test.go +++ b/testing/go/dolt_tables_test.go @@ -38,7 +38,6 @@ func TestUserSpaceDoltTables(t *testing.T) { Expected: []sql.Row{{"main"}}, }, { - Skip: true, // TODO: referencing items outside the schema or database is not yet supported Query: `SELECT dolt.branches.name FROM dolt.branches`, Expected: []sql.Row{{"main"}}, }, @@ -213,9 +212,8 @@ func TestUserSpaceDoltTables(t *testing.T) { Expected: []sql.Row{{"public.test", "id"}}, }, { - Skip: true, // TODO: referencing items outside the schema or database is not yet supported - Query: `SELECT dolt.column_diff.commit_hash FROM dolt.column_diff`, - Expected: []sql.Row{}, + Query: `SELECT dolt.column_diff.table_name FROM dolt.column_diff`, + Expected: []sql.Row{{"public.test"}}, }, { Query: `SELECT dolt_column_diff.table_name, dolt_column_diff.column_name FROM dolt_column_diff`, @@ -291,7 +289,6 @@ func TestUserSpaceDoltTables(t *testing.T) { Expected: []sql.Row{{2}}, }, { - Skip: true, // TODO: referencing items outside the schema or database is not yet supported Query: `SELECT dolt.commit_ancestors.parent_index FROM dolt.commit_ancestors`, Expected: []sql.Row{{0}, {0}}, }, @@ -469,7 +466,6 @@ func TestUserSpaceDoltTables(t *testing.T) { Expected: []sql.Row{{2}}, }, { - Skip: true, // TODO: referencing items outside the schema or database is not yet supported Query: `SELECT dolt.commits.message FROM dolt.commits`, Expected: []sql.Row{{"CREATE DATABASE"}, {"Initialize data repository"}}, }, @@ -562,7 +558,6 @@ func TestUserSpaceDoltTables(t *testing.T) { Expected: []sql.Row{{"test", Numeric("1")}}, }, { - Skip: true, // TODO: referencing items outside the schema or database is not yet supported Query: `SELECT dolt.conflicts.table FROM dolt.conflicts`, Expected: []sql.Row{{"test"}}, }, @@ -771,7 +766,6 @@ func TestUserSpaceDoltTables(t *testing.T) { Expected: []sql.Row{{"test", Numeric("2")}}, }, { - Skip: true, // TODO: referencing items outside the schema or database is not yet supported Query: `SELECT dolt.constraint_violations.table FROM dolt.constraint_violations`, Expected: []sql.Row{{"test"}}, }, @@ -982,7 +976,6 @@ func TestUserSpaceDoltTables(t *testing.T) { }, }, { - Skip: true, // TODO: referencing items outside the schema or database is not yet supported Query: `SELECT dolt.docs.doc_name FROM dolt.docs`, Expected: []sql.Row{{"README.md"}}, }, @@ -1137,7 +1130,6 @@ func TestUserSpaceDoltTables(t *testing.T) { Expected: []sql.Row{{"public.test"}}, }, { - Skip: true, // TODO: referencing items outside the schema or database is not yet supported Query: `SELECT dolt.diff.table_name FROM dolt.diff`, Expected: []sql.Row{{"public.test"}}, }, @@ -1687,7 +1679,6 @@ func TestUserSpaceDoltTables(t *testing.T) { Expected: []sql.Row{{"f"}}, }, { - Skip: true, // TODO: referencing items outside the schema or database is not yet supported Query: `SELECT dolt.merge_status.is_merging FROM dolt.merge_status`, Expected: []sql.Row{{"f"}}, }, @@ -1924,7 +1915,6 @@ func TestUserSpaceDoltTables(t *testing.T) { Expected: []sql.Row{}, }, { - Skip: true, // TODO: referencing items outside the schema or database is not yet supported Query: `SELECT dolt.status.table_name FROM dolt.status`, Expected: []sql.Row{{"public.t"}}, }, @@ -2005,7 +1995,6 @@ func TestUserSpaceDoltTables(t *testing.T) { Expected: []sql.Row{{"v1"}}, }, { - Skip: true, // TODO: referencing items outside the schema or database is not yet supported Query: `SELECT dolt.tags.tag_name FROM dolt.tags`, Expected: []sql.Row{{"v1"}}, }, @@ -2336,7 +2325,6 @@ func TestUserSpaceDoltTables(t *testing.T) { Expected: []sql.Row{}, }, { - Skip: true, // TODO: referencing items outside the schema or database is not yet supported Query: `SELECT dolt.remote_branches.name FROM dolt.remote_branches`, Expected: []sql.Row{}, }, @@ -2417,7 +2405,6 @@ func TestUserSpaceDoltTables(t *testing.T) { Expected: []sql.Row{{"origin"}}, }, { - Skip: true, // TODO: referencing items outside the schema or database is not yet supported Query: `SELECT dolt.remotes.name FROM dolt.remotes`, Expected: []sql.Row{{"origin"}}, }, @@ -2507,7 +2494,6 @@ func TestUserSpaceDoltTables(t *testing.T) { Expected: []sql.Row{{"test"}}, }, { - Skip: true, // TODO: referencing items outside the schema or database is not yet supported Query: `SELECT dolt.schema_conflicts.table_name FROM dolt.schema_conflicts`, Expected: []sql.Row{{"test"}}, }, diff --git a/testing/go/insert_test.go b/testing/go/insert_test.go index a15d871ef1..4ab34bcd0e 100755 --- a/testing/go/insert_test.go +++ b/testing/go/insert_test.go @@ -191,6 +191,8 @@ func TestInsert(t *testing.T) { "CREATE TABLE t (i serial, j INT)", "CREATE TABLE u (u uuid DEFAULT 'ac1f3e2d-1e4b-4d3e-8b1f-2b7f1e7f0e3d', j INT)", "CREATE TABLE s (v1 varchar DEFAULT 'hello', v2 varchar DEFAULT 'world')", + "CREATE SCHEMA ts", + "CREATE TABLE ts.t (i serial, j INT)", }, Assertions: []ScriptTestAssertion{ { @@ -244,6 +246,36 @@ func TestInsert(t *testing.T) { Query: "INSERT INTO t (j) VALUES (5), (6), (7) RETURNING i, doesnotexist(j)", ExpectedErr: "function: 'doesnotexist' not found", }, + { + Query: "INSERT INTO public.t (j) VALUES (8) RETURNING t.j", + Expected: []sql.Row{{8}}, + }, + { + Query: "INSERT INTO public.t (j) VALUES (9) RETURNING public.t.j", + Expected: []sql.Row{{9}}, + }, + { + Query: "INSERT INTO ts.t (j) VALUES (10) RETURNING ts.t.j", + Expected: []sql.Row{{10}}, + }, + { + Skip: true, // TODO: unable to find field with index 2 in row of 2 columns + Query: "INSERT INTO public.t (j) VALUES ($1) RETURNING j;", + BindVars: []any{11}, + Expected: []sql.Row{{11}}, + }, + { + Skip: true, // TODO: unable to find field with index 2 in row of 2 columns + Query: "INSERT INTO public.t (j) VALUES ($1) RETURNING t.j;", + BindVars: []any{12}, + Expected: []sql.Row{{12}}, + }, + { + Skip: true, // TODO: unable to find field with index 2 in row of 2 columns + Query: "INSERT INTO public.t (j) VALUES ($1) RETURNING public.t.j;", + BindVars: []any{13}, + Expected: []sql.Row{{13}}, + }, }, }, {