-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: create specific metadata queries for PG (#759)
* fix: create specific metadata queries for PG Creates specific metadata queries for PostgreSQL dialect databases and removes the use of the /*GSQL*/ header in the existing metadata queries. * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * fix: linting Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
6fca6b3
commit caffda0
Showing
21 changed files
with
1,186 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
src/main/resources/com/google/cloud/spanner/jdbc/DatabaseMetaData_GetColumns.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
/*GSQL*/ | ||
/* | ||
* Copyright 2019 Google LLC | ||
* | ||
|
1 change: 0 additions & 1 deletion
1
src/main/resources/com/google/cloud/spanner/jdbc/DatabaseMetaData_GetCrossReferences.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
/*GSQL*/ | ||
/* | ||
* Copyright 2019 Google LLC | ||
* | ||
|
1 change: 0 additions & 1 deletion
1
src/main/resources/com/google/cloud/spanner/jdbc/DatabaseMetaData_GetExportedKeys.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
/*GSQL*/ | ||
/* | ||
* Copyright 2019 Google LLC | ||
* | ||
|
1 change: 0 additions & 1 deletion
1
src/main/resources/com/google/cloud/spanner/jdbc/DatabaseMetaData_GetImportedKeys.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
/*GSQL*/ | ||
/* | ||
* Copyright 2019 Google LLC | ||
* | ||
|
1 change: 0 additions & 1 deletion
1
src/main/resources/com/google/cloud/spanner/jdbc/DatabaseMetaData_GetIndexInfo.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
/*GSQL*/ | ||
/* | ||
* Copyright 2019 Google LLC | ||
* | ||
|
1 change: 0 additions & 1 deletion
1
src/main/resources/com/google/cloud/spanner/jdbc/DatabaseMetaData_GetPrimaryKeys.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
/*GSQL*/ | ||
/* | ||
* Copyright 2019 Google LLC | ||
* | ||
|
1 change: 0 additions & 1 deletion
1
src/main/resources/com/google/cloud/spanner/jdbc/DatabaseMetaData_GetSchemas.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
/*GSQL*/ | ||
/* | ||
* Copyright 2019 Google LLC | ||
* | ||
|
1 change: 0 additions & 1 deletion
1
src/main/resources/com/google/cloud/spanner/jdbc/DatabaseMetaData_GetTables.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
/*GSQL*/ | ||
/* | ||
* Copyright 2019 Google LLC | ||
* | ||
|
81 changes: 81 additions & 0 deletions
81
src/main/resources/com/google/cloud/spanner/jdbc/postgresql/DatabaseMetaData_GetColumns.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
SELECT TABLE_CATALOG AS "TABLE_CAT", TABLE_SCHEMA AS "TABLE_SCHEM", TABLE_NAME AS "TABLE_NAME", COLUMN_NAME AS "COLUMN_NAME", | ||
CASE | ||
WHEN DATA_TYPE LIKE 'ARRAY' THEN 2003 | ||
WHEN DATA_TYPE = 'boolean' THEN 16 | ||
WHEN DATA_TYPE LIKE 'bytea' THEN -2 | ||
WHEN DATA_TYPE = 'date' THEN 91 | ||
WHEN DATA_TYPE = 'double precision' THEN 8 | ||
WHEN DATA_TYPE = 'bigint' THEN -5 | ||
WHEN DATA_TYPE = 'numeric' THEN 2 | ||
WHEN DATA_TYPE LIKE 'character varying' THEN -9 | ||
WHEN DATA_TYPE = 'jsonb' THEN -9 | ||
WHEN DATA_TYPE = 'timestamp with time zone' THEN 93 | ||
END AS "DATA_TYPE", | ||
DATA_TYPE AS "TYPE_NAME", | ||
CASE | ||
WHEN DATA_TYPE LIKE 'ARRAY' THEN 0 | ||
WHEN DATA_TYPE = 'boolean' THEN NULL | ||
WHEN DATA_TYPE LIKE 'bytea' THEN 10485760 | ||
WHEN DATA_TYPE = 'date' THEN 10 | ||
WHEN DATA_TYPE = 'double precision' THEN 15 | ||
WHEN DATA_TYPE = 'bigint' THEN 19 | ||
WHEN DATA_TYPE = 'numeric' THEN 15 | ||
WHEN DATA_TYPE LIKE 'character varying' THEN CHARACTER_MAXIMUM_LENGTH | ||
WHEN DATA_TYPE = 'jsonb' THEN 2621440 | ||
WHEN DATA_TYPE = 'timestamp with time zone' THEN 35 | ||
END AS "COLUMN_SIZE", | ||
0 AS "BUFFER_LENGTH", | ||
CASE | ||
WHEN DATA_TYPE LIKE 'double precision' THEN 16 | ||
WHEN DATA_TYPE LIKE 'numeric' THEN 16383 | ||
ELSE NULL | ||
END AS "DECIMAL_DIGITS", | ||
CASE | ||
WHEN DATA_TYPE LIKE 'bigint' THEN 10 | ||
WHEN DATA_TYPE LIKE 'numeric' THEN 10 | ||
WHEN DATA_TYPE LIKE 'double precision' THEN 2 | ||
ELSE NULL | ||
END AS "NUM_PREC_RADIX", | ||
CASE | ||
WHEN IS_NULLABLE = 'YES' THEN 1 | ||
WHEN IS_NULLABLE = 'NO' THEN 0 | ||
ELSE 2 | ||
END AS "NULLABLE", | ||
NULL AS "REMARKS", | ||
NULL AS "COLUMN_DEF", | ||
0 AS "SQL_DATA_TYPE", | ||
0 AS "SQL_DATETIME_SUB", | ||
CHARACTER_MAXIMUM_LENGTH AS "CHAR_OCTET_LENGTH", | ||
ORDINAL_POSITION AS "ORDINAL_POSITION", | ||
IS_NULLABLE AS "IS_NULLABLE", | ||
NULL AS "SCOPE_CATALOG", | ||
NULL AS "SCOPE_SCHEMA", | ||
NULL AS "SCOPE_TABLE", | ||
NULL AS "SOURCE_DATA_TYPE", | ||
'NO' AS "IS_AUTOINCREMENT", | ||
CASE | ||
WHEN (IS_GENERATED = 'NEVER') THEN 'NO' | ||
ELSE 'YES' | ||
END AS "IS_GENERATEDCOLUMN" | ||
FROM INFORMATION_SCHEMA.COLUMNS C | ||
WHERE UPPER(C.TABLE_CATALOG) LIKE ? | ||
AND UPPER(C.TABLE_SCHEMA) LIKE ? | ||
AND UPPER(C.TABLE_NAME) LIKE ? | ||
AND UPPER(C.COLUMN_NAME) LIKE ? | ||
ORDER BY TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, ORDINAL_POSITION |
31 changes: 31 additions & 0 deletions
31
...esources/com/google/cloud/spanner/jdbc/postgresql/DatabaseMetaData_GetCrossReferences.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
SELECT PARENT.TABLE_CATALOG AS "PKTABLE_CAT", PARENT.TABLE_SCHEMA AS "PKTABLE_SCHEM", PARENT.TABLE_NAME AS "PKTABLE_NAME", | ||
PARENT.COLUMN_NAME AS "PKCOLUMN_NAME", CHILD.TABLE_CATALOG AS "FKTABLE_CAT", CHILD.TABLE_SCHEMA AS "FKTABLE_SCHEM", | ||
CHILD.TABLE_NAME AS "FKTABLE_NAME", CHILD.COLUMN_NAME AS "FKCOLUMN_NAME", CHILD.ORDINAL_POSITION AS "KEY_SEQ", 3 AS "UPDATE_RULE", | ||
3 AS "DELETE_RULE", CONSTRAINTS.CONSTRAINT_NAME AS "FK_NAME", CONSTRAINTS.UNIQUE_CONSTRAINT_NAME AS "PK_NAME", | ||
7 AS "DEFERRABILITY" | ||
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS CONSTRAINTS | ||
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE CHILD ON CONSTRAINTS.CONSTRAINT_CATALOG=CHILD.CONSTRAINT_CATALOG AND CONSTRAINTS.CONSTRAINT_SCHEMA= CHILD.CONSTRAINT_SCHEMA AND CONSTRAINTS.CONSTRAINT_NAME= CHILD.CONSTRAINT_NAME | ||
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE PARENT ON CONSTRAINTS.UNIQUE_CONSTRAINT_CATALOG=PARENT.CONSTRAINT_CATALOG AND CONSTRAINTS.UNIQUE_CONSTRAINT_SCHEMA=PARENT.CONSTRAINT_SCHEMA AND CONSTRAINTS.UNIQUE_CONSTRAINT_NAME=PARENT.CONSTRAINT_NAME AND PARENT.ORDINAL_POSITION=CHILD.POSITION_IN_UNIQUE_CONSTRAINT | ||
WHERE UPPER(PARENT.TABLE_CATALOG) LIKE ? | ||
AND UPPER(PARENT.TABLE_SCHEMA) LIKE ? | ||
AND UPPER(PARENT.TABLE_NAME) LIKE ? | ||
AND UPPER(CHILD.TABLE_CATALOG) LIKE ? | ||
AND UPPER(CHILD.TABLE_SCHEMA) LIKE ? | ||
AND UPPER(CHILD.TABLE_NAME) LIKE ? | ||
ORDER BY CHILD.TABLE_CATALOG, CHILD.TABLE_SCHEMA, CHILD.TABLE_NAME, CHILD.ORDINAL_POSITION |
31 changes: 31 additions & 0 deletions
31
...n/resources/com/google/cloud/spanner/jdbc/postgresql/DatabaseMetaData_GetExportedKeys.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
SELECT PARENT.TABLE_CATALOG AS "PKTABLE_CAT", PARENT.TABLE_SCHEMA AS "PKTABLE_SCHEM", PARENT.TABLE_NAME AS "PKTABLE_NAME", | ||
PARENT.COLUMN_NAME AS "PKCOLUMN_NAME", CHILD.TABLE_CATALOG AS "FKTABLE_CAT", CHILD.TABLE_SCHEMA AS "FKTABLE_SCHEM", | ||
CHILD.TABLE_NAME AS "FKTABLE_NAME", CHILD.COLUMN_NAME AS "FKCOLUMN_NAME", | ||
CHILD.ORDINAL_POSITION AS "KEY_SEQ", | ||
1 AS "UPDATE_RULE", -- 1 = importedKeyRestrict | ||
1 AS "DELETE_RULE", -- 1 = importedKeyRestrict | ||
CONSTRAINTS.CONSTRAINT_NAME AS "FK_NAME", CONSTRAINTS.UNIQUE_CONSTRAINT_NAME AS "PK_NAME", | ||
7 AS "DEFERRABILITY" -- 7 = importedKeyNotDeferrable | ||
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS CONSTRAINTS | ||
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE CHILD ON CONSTRAINTS.CONSTRAINT_CATALOG=CHILD.CONSTRAINT_CATALOG AND CONSTRAINTS.CONSTRAINT_SCHEMA= CHILD.CONSTRAINT_SCHEMA AND CONSTRAINTS.CONSTRAINT_NAME= CHILD.CONSTRAINT_NAME | ||
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE PARENT ON CONSTRAINTS.UNIQUE_CONSTRAINT_CATALOG=PARENT.CONSTRAINT_CATALOG AND CONSTRAINTS.UNIQUE_CONSTRAINT_SCHEMA=PARENT.CONSTRAINT_SCHEMA AND CONSTRAINTS.UNIQUE_CONSTRAINT_NAME=PARENT.CONSTRAINT_NAME AND PARENT.ORDINAL_POSITION=CHILD.POSITION_IN_UNIQUE_CONSTRAINT | ||
WHERE UPPER(PARENT.TABLE_CATALOG) LIKE ? | ||
AND UPPER(PARENT.TABLE_SCHEMA) LIKE ? | ||
AND UPPER(PARENT.TABLE_NAME) LIKE ? | ||
ORDER BY CHILD.TABLE_CATALOG, CHILD.TABLE_SCHEMA, CHILD.TABLE_NAME, CHILD.ORDINAL_POSITION |
31 changes: 31 additions & 0 deletions
31
...n/resources/com/google/cloud/spanner/jdbc/postgresql/DatabaseMetaData_GetImportedKeys.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
SELECT PARENT.TABLE_CATALOG AS "PKTABLE_CAT", PARENT.TABLE_SCHEMA AS "PKTABLE_SCHEM", PARENT.TABLE_NAME AS "PKTABLE_NAME", | ||
PARENT.COLUMN_NAME AS "PKCOLUMN_NAME", CHILD.TABLE_CATALOG AS "FKTABLE_CAT", CHILD.TABLE_SCHEMA AS "FKTABLE_SCHEM", | ||
CHILD.TABLE_NAME AS "FKTABLE_NAME", CHILD.COLUMN_NAME AS "FKCOLUMN_NAME", | ||
CHILD.ORDINAL_POSITION AS "KEY_SEQ", | ||
1 AS "UPDATE_RULE", -- 1 = importedKeyRestrict | ||
1 AS "DELETE_RULE", -- 1 = importedKeyRestrict | ||
CONSTRAINTS.CONSTRAINT_NAME AS "FK_NAME", CONSTRAINTS.UNIQUE_CONSTRAINT_NAME AS "PK_NAME", | ||
7 AS "DEFERRABILITY" -- 7 = importedKeyNotDeferrable | ||
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS CONSTRAINTS | ||
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE CHILD ON CONSTRAINTS.CONSTRAINT_CATALOG=CHILD.CONSTRAINT_CATALOG AND CONSTRAINTS.CONSTRAINT_SCHEMA= CHILD.CONSTRAINT_SCHEMA AND CONSTRAINTS.CONSTRAINT_NAME= CHILD.CONSTRAINT_NAME | ||
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE PARENT ON CONSTRAINTS.UNIQUE_CONSTRAINT_CATALOG=PARENT.CONSTRAINT_CATALOG AND CONSTRAINTS.UNIQUE_CONSTRAINT_SCHEMA=PARENT.CONSTRAINT_SCHEMA AND CONSTRAINTS.UNIQUE_CONSTRAINT_NAME=PARENT.CONSTRAINT_NAME AND PARENT.ORDINAL_POSITION=CHILD.POSITION_IN_UNIQUE_CONSTRAINT | ||
WHERE UPPER(CHILD.TABLE_CATALOG) LIKE ? | ||
AND UPPER(CHILD.TABLE_SCHEMA) LIKE ? | ||
AND UPPER(CHILD.TABLE_NAME) LIKE ? | ||
ORDER BY PARENT.TABLE_CATALOG, PARENT.TABLE_SCHEMA, PARENT.TABLE_NAME, CHILD.ORDINAL_POSITION |
36 changes: 36 additions & 0 deletions
36
...main/resources/com/google/cloud/spanner/jdbc/postgresql/DatabaseMetaData_GetIndexInfo.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
SELECT IDX.TABLE_CATALOG AS "TABLE_CAT", IDX.TABLE_SCHEMA AS "TABLE_SCHEM", IDX.TABLE_NAME AS "TABLE_NAME", | ||
CASE WHEN IS_UNIQUE='YES' THEN FALSE ELSE TRUE END AS "NON_UNIQUE", | ||
IDX.TABLE_CATALOG AS "INDEX_QUALIFIER", IDX.INDEX_NAME AS "INDEX_NAME", | ||
2 AS "TYPE", | ||
ORDINAL_POSITION AS "ORDINAL_POSITION", COLUMN_NAME AS "COLUMN_NAME", SUBSTR(COLUMN_ORDERING, 1, 1) AS "ASC_OR_DESC", | ||
-1 AS "CARDINALITY", -- Not supported | ||
-1 AS "PAGES", -- Not supported | ||
NULL AS "FILTER_CONDITION" | ||
FROM INFORMATION_SCHEMA.INDEXES IDX | ||
INNER JOIN INFORMATION_SCHEMA.INDEX_COLUMNS COL | ||
ON IDX.TABLE_CATALOG=COL.TABLE_CATALOG | ||
AND IDX.TABLE_SCHEMA=COL.TABLE_SCHEMA | ||
AND IDX.TABLE_NAME=COL.TABLE_NAME | ||
AND IDX.INDEX_NAME=COL.INDEX_NAME | ||
WHERE UPPER(IDX.TABLE_CATALOG) LIKE ? | ||
AND UPPER(IDX.TABLE_SCHEMA) LIKE ? | ||
AND UPPER(IDX.TABLE_NAME) LIKE ? | ||
AND UPPER(IDX.INDEX_NAME) LIKE ? | ||
AND UPPER(IS_UNIQUE) LIKE ? | ||
ORDER BY IDX.TABLE_NAME, IS_UNIQUE DESC, IDX.INDEX_NAME, CASE WHEN ORDINAL_POSITION IS NULL THEN 0 ELSE ORDINAL_POSITION END |
29 changes: 29 additions & 0 deletions
29
...in/resources/com/google/cloud/spanner/jdbc/postgresql/DatabaseMetaData_GetPrimaryKeys.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
SELECT IDX.TABLE_CATALOG AS "TABLE_CAT", IDX.TABLE_SCHEMA AS "TABLE_SCHEM", IDX.TABLE_NAME AS "TABLE_NAME", | ||
COLS.COLUMN_NAME AS "COLUMN_NAME", ORDINAL_POSITION AS "KEY_SEQ", IDX.INDEX_NAME AS "PK_NAME" | ||
FROM INFORMATION_SCHEMA.INDEXES IDX | ||
INNER JOIN INFORMATION_SCHEMA.INDEX_COLUMNS COLS | ||
ON IDX.TABLE_CATALOG=COLS.TABLE_CATALOG | ||
AND IDX.TABLE_SCHEMA=COLS.TABLE_SCHEMA | ||
AND IDX.TABLE_NAME=COLS.TABLE_NAME | ||
AND IDX.INDEX_NAME=COLS.INDEX_NAME | ||
WHERE IDX.INDEX_TYPE='PRIMARY_KEY' | ||
AND UPPER(IDX.TABLE_CATALOG) LIKE ? | ||
AND UPPER(IDX.TABLE_SCHEMA) LIKE ? | ||
AND UPPER(IDX.TABLE_NAME) LIKE ? | ||
ORDER BY COLS.ORDINAL_POSITION |
Oops, something went wrong.