Skip to content

Commit

Permalink
Merge pull request #41447 from jordanlewis/backport19.2-41323
Browse files Browse the repository at this point in the history
release-19.2: sql: bevy of fixes for ActiveRecord compatibility
  • Loading branch information
jordanlewis committed Oct 8, 2019
2 parents edcec3b + c215049 commit 58b9c0b
Show file tree
Hide file tree
Showing 21 changed files with 289 additions and 157 deletions.
6 changes: 4 additions & 2 deletions pkg/ccl/importccl/import_table_creation.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,10 @@ func (so *importSequenceOperators) ParseQualifiedTableName(
}

// Implements the tree.EvalDatabase interface.
func (so *importSequenceOperators) ResolveTableName(ctx context.Context, tn *tree.TableName) error {
return errSequenceOperators
func (so *importSequenceOperators) ResolveTableName(
ctx context.Context, tn *tree.TableName,
) (tree.ID, error) {
return 0, errSequenceOperators
}

// Implements the tree.EvalDatabase interface.
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/logictest/testdata/logic_test/builtin_function
Original file line number Diff line number Diff line change
Expand Up @@ -1922,7 +1922,7 @@ CREATE TABLE test.pg_indexdef_test (a INT, UNIQUE INDEX pg_indexdef_idx (a ASC),
query T
SELECT pg_catalog.pg_get_indexdef((SELECT oid from pg_class WHERE relname='pg_indexdef_idx'))
----
CREATE UNIQUE INDEX pg_indexdef_idx ON test.public.pg_indexdef_test (a ASC)
CREATE UNIQUE INDEX pg_indexdef_idx ON test.public.pg_indexdef_test USING btree (a ASC)

query T
SELECT pg_catalog.pg_get_indexdef(0, 0, true)
Expand All @@ -1932,15 +1932,15 @@ NULL
query T
SELECT pg_catalog.pg_get_indexdef((SELECT oid from pg_class WHERE relname='pg_indexdef_idx'), 0, true)
----
CREATE UNIQUE INDEX pg_indexdef_idx ON test.public.pg_indexdef_test (a ASC)
CREATE UNIQUE INDEX pg_indexdef_idx ON test.public.pg_indexdef_test USING btree (a ASC)

statement ok
CREATE TABLE test.pg_indexdef_test_cols (a INT, b INT, UNIQUE INDEX pg_indexdef_cols_idx (a ASC, b DESC), INDEX other (a DESC))

query T
SELECT pg_catalog.pg_get_indexdef((SELECT oid from pg_class WHERE relname='pg_indexdef_cols_idx'), 0, true)
----
CREATE UNIQUE INDEX pg_indexdef_cols_idx ON test.public.pg_indexdef_test_cols (a ASC, b DESC)
CREATE UNIQUE INDEX pg_indexdef_cols_idx ON test.public.pg_indexdef_test_cols USING btree (a ASC, b DESC)

query T
SELECT pg_catalog.pg_get_indexdef((SELECT oid from pg_class WHERE relname='pg_indexdef_cols_idx'), 1, true)
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/logictest/testdata/logic_test/grant_table
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ test pg_catalog pg_am public S
test pg_catalog pg_attrdef public SELECT
test pg_catalog pg_attribute public SELECT
test pg_catalog pg_auth_members public SELECT
test pg_catalog pg_available_extensions public SELECT
test pg_catalog pg_cast public SELECT
test pg_catalog pg_class public SELECT
test pg_catalog pg_collation public SELECT
Expand Down
5 changes: 5 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/information_schema
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ pg_catalog pg_am
pg_catalog pg_attrdef
pg_catalog pg_attribute
pg_catalog pg_auth_members
pg_catalog pg_available_extensions
pg_catalog pg_cast
pg_catalog pg_class
pg_catalog pg_collation
Expand Down Expand Up @@ -410,6 +411,7 @@ pg_am
pg_attrdef
pg_attribute
pg_auth_members
pg_available_extensions
pg_cast
pg_class
pg_collation
Expand Down Expand Up @@ -554,6 +556,7 @@ system pg_catalog pg_am SYSTEM VIE
system pg_catalog pg_attrdef SYSTEM VIEW NO 1
system pg_catalog pg_attribute SYSTEM VIEW NO 1
system pg_catalog pg_auth_members SYSTEM VIEW NO 1
system pg_catalog pg_available_extensions SYSTEM VIEW NO 1
system pg_catalog pg_cast SYSTEM VIEW NO 1
system pg_catalog pg_class SYSTEM VIEW NO 1
system pg_catalog pg_collation SYSTEM VIEW NO 1
Expand Down Expand Up @@ -1354,6 +1357,7 @@ NULL public system pg_catalog pg_am
NULL public system pg_catalog pg_attrdef SELECT NULL YES
NULL public system pg_catalog pg_attribute SELECT NULL YES
NULL public system pg_catalog pg_auth_members SELECT NULL YES
NULL public system pg_catalog pg_available_extensions SELECT NULL YES
NULL public system pg_catalog pg_cast SELECT NULL YES
NULL public system pg_catalog pg_class SELECT NULL YES
NULL public system pg_catalog pg_collation SELECT NULL YES
Expand Down Expand Up @@ -1644,6 +1648,7 @@ NULL public system pg_catalog pg_am
NULL public system pg_catalog pg_attrdef SELECT NULL YES
NULL public system pg_catalog pg_attribute SELECT NULL YES
NULL public system pg_catalog pg_auth_members SELECT NULL YES
NULL public system pg_catalog pg_available_extensions SELECT NULL YES
NULL public system pg_catalog pg_cast SELECT NULL YES
NULL public system pg_catalog pg_class SELECT NULL YES
NULL public system pg_catalog pg_collation SELECT NULL YES
Expand Down
29 changes: 27 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/orms
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ GROUP BY i.relname,
ORDER BY i.relname
----
name primary unique indkey column_indexes column_names definition
customers_id_idx false false 2 {1,2} {name,id} CREATE INDEX customers_id_idx ON test.public.customers (id ASC)
primary true true 1 {1,2} {name,id} CREATE UNIQUE INDEX "primary" ON test.public.customers (name ASC)
customers_id_idx false false 2 {1,2} {name,id} CREATE INDEX customers_id_idx ON test.public.customers USING btree (id ASC)
primary true true 1 {1,2} {name,id} CREATE UNIQUE INDEX "primary" ON test.public.customers USING btree (name ASC)


query TT colnames
Expand Down Expand Up @@ -137,3 +137,28 @@ AND t.relname = 'b'
AND i.relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname = ANY (current_schemas(false)))
----
1

statement ok
CREATE TABLE c (a INT, b INT, PRIMARY KEY (a, b))

# ActiveRecord query for determining primary key cols.
query T
SELECT
a.attname
FROM
(
SELECT
indrelid, indkey, generate_subscripts(indkey, 1) AS idx
FROM
pg_index
WHERE
indrelid = '"c"'::REGCLASS AND indisprimary
)
AS i
JOIN pg_attribute AS a ON
a.attrelid = i.indrelid AND a.attnum = i.indkey[i.idx]
ORDER BY
i.idx
----
a
b
Loading

0 comments on commit 58b9c0b

Please sign in to comment.