21 files changed

+1186
-161
lines changed
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.google.auth.Credentials;
2020
import com.google.auth.ServiceAccountSigner;
2121
import com.google.auth.oauth2.UserCredentials;
22+
import com.google.cloud.spanner.Dialect;
2223
import com.google.cloud.spanner.ResultSets;
2324
import com.google.cloud.spanner.Struct;
2425
import com.google.cloud.spanner.Type;
@@ -48,8 +49,16 @@ class JdbcDatabaseMetaData extends AbstractJdbcWrapper implements DatabaseMetaDa
4849
private static final String PRODUCT_NAME = "Google Cloud Spanner";
4950

5051
@VisibleForTesting
51-
static String readSqlFromFile(String filename) {
52-
InputStream in = JdbcDatabaseMetaData.class.getResourceAsStream(filename);
52+
static String readSqlFromFile(String filename, Dialect dialect) {
53+
InputStream in;
54+
switch (dialect) {
55+
case POSTGRESQL:
56+
in = JdbcDatabaseMetaData.class.getResourceAsStream("postgresql/" + filename);
57+
break;
58+
case GOOGLE_STANDARD_SQL:
59+
default:
60+
in = JdbcDatabaseMetaData.class.getResourceAsStream(filename);
61+
}
5362
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
5463
StringBuilder builder = new StringBuilder();
5564
try (Scanner scanner = new Scanner(reader)) {
@@ -743,7 +752,7 @@ private JdbcPreparedStatement prepareStatementReplaceNullWithAnyString(
743752
public ResultSet getTables(
744753
String catalog, String schemaPattern, String tableNamePattern, String[] types)
745754
throws SQLException {
746-
String sql = readSqlFromFile("DatabaseMetaData_GetTables.sql");
755+
String sql = readSqlFromFile("DatabaseMetaData_GetTables.sql", connection.getDialect());
747756
String type1;
748757
String type2;
749758
if (types == null || types.length == 0) {
@@ -789,7 +798,7 @@ public ResultSet getTableTypes() {
789798
public ResultSet getColumns(
790799
String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern)
791800
throws SQLException {
792-
String sql = readSqlFromFile("DatabaseMetaData_GetColumns.sql");
801+
String sql = readSqlFromFile("DatabaseMetaData_GetColumns.sql", connection.getDialect());
793802
JdbcPreparedStatement statement =
794803
prepareStatementReplaceNullWithAnyString(
795804
sql, catalog, schemaPattern, tableNamePattern, columnNamePattern);
@@ -858,7 +867,7 @@ private ResultSet getEmptyColumnsResultSet() {
858867
@Override
859868
public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException {
860869
JdbcPreconditions.checkArgument(table != null, "table may not be null");
861-
String sql = readSqlFromFile("DatabaseMetaData_GetPrimaryKeys.sql");
870+
String sql = readSqlFromFile("DatabaseMetaData_GetPrimaryKeys.sql", connection.getDialect());
862871
JdbcPreparedStatement statement =
863872
prepareStatementReplaceNullWithAnyString(sql, catalog, schema, table);
864873
return statement.executeQueryWithOptions(InternalMetadataQuery.INSTANCE);
@@ -868,7 +877,7 @@ public ResultSet getPrimaryKeys(String catalog, String schema, String table) thr
868877
public ResultSet getImportedKeys(String catalog, String schema, String table)
869878
throws SQLException {
870879
JdbcPreconditions.checkArgument(table != null, "table may not be null");
871-
String sql = readSqlFromFile("DatabaseMetaData_GetImportedKeys.sql");
880+
String sql = readSqlFromFile("DatabaseMetaData_GetImportedKeys.sql", connection.getDialect());
872881
JdbcPreparedStatement statement =
873882
prepareStatementReplaceNullWithAnyString(sql, catalog, schema, table);
874883
return statement.executeQueryWithOptions(InternalMetadataQuery.INSTANCE);
@@ -878,7 +887,7 @@ public ResultSet getImportedKeys(String catalog, String schema, String table)
878887
public ResultSet getExportedKeys(String catalog, String schema, String table)
879888
throws SQLException {
880889
JdbcPreconditions.checkArgument(table != null, "table may not be null");
881-
String sql = readSqlFromFile("DatabaseMetaData_GetExportedKeys.sql");
890+
String sql = readSqlFromFile("DatabaseMetaData_GetExportedKeys.sql", connection.getDialect());
882891
JdbcPreparedStatement statement =
883892
prepareStatementReplaceNullWithAnyString(sql, catalog, schema, table);
884893
return statement.executeQueryWithOptions(InternalMetadataQuery.INSTANCE);
@@ -893,7 +902,8 @@ public ResultSet getCrossReference(
893902
String foreignSchema,
894903
String foreignTable)
895904
throws SQLException {
896-
String sql = readSqlFromFile("DatabaseMetaData_GetCrossReferences.sql");
905+
String sql =
906+
readSqlFromFile("DatabaseMetaData_GetCrossReferences.sql", connection.getDialect());
897907
JdbcPreparedStatement statement =
898908
prepareStatementReplaceNullWithAnyString(
899909
sql,
@@ -1251,7 +1261,7 @@ public ResultSet getIndexInfo(String catalog, String schema, String indexName)
12511261
private ResultSet getIndexInfo(
12521262
String catalog, String schema, String table, String indexName, boolean unique)
12531263
throws SQLException {
1254-
String sql = readSqlFromFile("DatabaseMetaData_GetIndexInfo.sql");
1264+
String sql = readSqlFromFile("DatabaseMetaData_GetIndexInfo.sql", connection.getDialect());
12551265
JdbcPreparedStatement statement =
12561266
prepareStatementReplaceNullWithAnyString(
12571267
sql, catalog, schema, table, indexName, unique ? "YES" : "%");
@@ -1467,7 +1477,7 @@ public RowIdLifetime getRowIdLifetime() {
14671477

14681478
@Override
14691479
public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException {
1470-
String sql = readSqlFromFile("DatabaseMetaData_GetSchemas.sql");
1480+
String sql = readSqlFromFile("DatabaseMetaData_GetSchemas.sql", connection.getDialect());
14711481
JdbcPreparedStatement statement =
14721482
prepareStatementReplaceNullWithAnyString(sql, catalog, schemaPattern);
14731483
return statement.executeQueryWithOptions(InternalMetadataQuery.INSTANCE);
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/*GSQL*/
21
/*
32
* Copyright 2019 Google LLC
43
*
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/*GSQL*/
21
/*
32
* Copyright 2019 Google LLC
43
*
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/*GSQL*/
21
/*
32
* Copyright 2019 Google LLC
43
*
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/*GSQL*/
21
/*
32
* Copyright 2019 Google LLC
43
*
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/*GSQL*/
21
/*
32
* Copyright 2019 Google LLC
43
*
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/*GSQL*/
21
/*
32
* Copyright 2019 Google LLC
43
*
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/*GSQL*/
21
/*
32
* Copyright 2019 Google LLC
43
*
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/*GSQL*/
21
/*
32
* Copyright 2019 Google LLC
43
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
SELECT TABLE_CATALOG AS "TABLE_CAT", TABLE_SCHEMA AS "TABLE_SCHEM", TABLE_NAME AS "TABLE_NAME", COLUMN_NAME AS "COLUMN_NAME",
18+
CASE
19+
WHEN DATA_TYPE LIKE 'ARRAY' THEN 2003
20+
WHEN DATA_TYPE = 'boolean' THEN 16
21+
WHEN DATA_TYPE LIKE 'bytea' THEN -2
22+
WHEN DATA_TYPE = 'date' THEN 91
23+
WHEN DATA_TYPE = 'double precision' THEN 8
24+
WHEN DATA_TYPE = 'bigint' THEN -5
25+
WHEN DATA_TYPE = 'numeric' THEN 2
26+
WHEN DATA_TYPE LIKE 'character varying' THEN -9
27+
WHEN DATA_TYPE = 'jsonb' THEN -9
28+
WHEN DATA_TYPE = 'timestamp with time zone' THEN 93
29+
END AS "DATA_TYPE",
30+
DATA_TYPE AS "TYPE_NAME",
31+
CASE
32+
WHEN DATA_TYPE LIKE 'ARRAY' THEN 0
33+
WHEN DATA_TYPE = 'boolean' THEN NULL
34+
WHEN DATA_TYPE LIKE 'bytea' THEN 10485760
35+
WHEN DATA_TYPE = 'date' THEN 10
36+
WHEN DATA_TYPE = 'double precision' THEN 15
37+
WHEN DATA_TYPE = 'bigint' THEN 19
38+
WHEN DATA_TYPE = 'numeric' THEN 15
39+
WHEN DATA_TYPE LIKE 'character varying' THEN CHARACTER_MAXIMUM_LENGTH
40+
WHEN DATA_TYPE = 'jsonb' THEN 2621440
41+
WHEN DATA_TYPE = 'timestamp with time zone' THEN 35
42+
END AS "COLUMN_SIZE",
43+
0 AS "BUFFER_LENGTH",
44+
CASE
45+
WHEN DATA_TYPE LIKE 'double precision' THEN 16
46+
WHEN DATA_TYPE LIKE 'numeric' THEN 16383
47+
ELSE NULL
48+
END AS "DECIMAL_DIGITS",
49+
CASE
50+
WHEN DATA_TYPE LIKE 'bigint' THEN 10
51+
WHEN DATA_TYPE LIKE 'numeric' THEN 10
52+
WHEN DATA_TYPE LIKE 'double precision' THEN 2
53+
ELSE NULL
54+
END AS "NUM_PREC_RADIX",
55+
CASE
56+
WHEN IS_NULLABLE = 'YES' THEN 1
57+
WHEN IS_NULLABLE = 'NO' THEN 0
58+
ELSE 2
59+
END AS "NULLABLE",
60+
NULL AS "REMARKS",
61+
NULL AS "COLUMN_DEF",
62+
0 AS "SQL_DATA_TYPE",
63+
0 AS "SQL_DATETIME_SUB",
64+
CHARACTER_MAXIMUM_LENGTH AS "CHAR_OCTET_LENGTH",
65+
ORDINAL_POSITION AS "ORDINAL_POSITION",
66+
IS_NULLABLE AS "IS_NULLABLE",
67+
NULL AS "SCOPE_CATALOG",
68+
NULL AS "SCOPE_SCHEMA",
69+
NULL AS "SCOPE_TABLE",
70+
NULL AS "SOURCE_DATA_TYPE",
71+
'NO' AS "IS_AUTOINCREMENT",
72+
CASE
73+
WHEN (IS_GENERATED = 'NEVER') THEN 'NO'
74+
ELSE 'YES'
75+
END AS "IS_GENERATEDCOLUMN"
76+
FROM INFORMATION_SCHEMA.COLUMNS C
77+
WHERE UPPER(C.TABLE_CATALOG) LIKE ?
78+
AND UPPER(C.TABLE_SCHEMA) LIKE ?
79+
AND UPPER(C.TABLE_NAME) LIKE ?
80+
AND UPPER(C.COLUMN_NAME) LIKE ?
81+
ORDER BY TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, ORDINAL_POSITION
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
SELECT PARENT.TABLE_CATALOG AS "PKTABLE_CAT", PARENT.TABLE_SCHEMA AS "PKTABLE_SCHEM", PARENT.TABLE_NAME AS "PKTABLE_NAME",
18+
PARENT.COLUMN_NAME AS "PKCOLUMN_NAME", CHILD.TABLE_CATALOG AS "FKTABLE_CAT", CHILD.TABLE_SCHEMA AS "FKTABLE_SCHEM",
19+
CHILD.TABLE_NAME AS "FKTABLE_NAME", CHILD.COLUMN_NAME AS "FKCOLUMN_NAME", CHILD.ORDINAL_POSITION AS "KEY_SEQ", 3 AS "UPDATE_RULE",
20+
3 AS "DELETE_RULE", CONSTRAINTS.CONSTRAINT_NAME AS "FK_NAME", CONSTRAINTS.UNIQUE_CONSTRAINT_NAME AS "PK_NAME",
21+
7 AS "DEFERRABILITY"
22+
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS CONSTRAINTS
23+
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
24+
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
25+
WHERE UPPER(PARENT.TABLE_CATALOG) LIKE ?
26+
AND UPPER(PARENT.TABLE_SCHEMA) LIKE ?
27+
AND UPPER(PARENT.TABLE_NAME) LIKE ?
28+
AND UPPER(CHILD.TABLE_CATALOG) LIKE ?
29+
AND UPPER(CHILD.TABLE_SCHEMA) LIKE ?
30+
AND UPPER(CHILD.TABLE_NAME) LIKE ?
31+
ORDER BY CHILD.TABLE_CATALOG, CHILD.TABLE_SCHEMA, CHILD.TABLE_NAME, CHILD.ORDINAL_POSITION
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
SELECT PARENT.TABLE_CATALOG AS "PKTABLE_CAT", PARENT.TABLE_SCHEMA AS "PKTABLE_SCHEM", PARENT.TABLE_NAME AS "PKTABLE_NAME",
18+
PARENT.COLUMN_NAME AS "PKCOLUMN_NAME", CHILD.TABLE_CATALOG AS "FKTABLE_CAT", CHILD.TABLE_SCHEMA AS "FKTABLE_SCHEM",
19+
CHILD.TABLE_NAME AS "FKTABLE_NAME", CHILD.COLUMN_NAME AS "FKCOLUMN_NAME",
20+
CHILD.ORDINAL_POSITION AS "KEY_SEQ",
21+
1 AS "UPDATE_RULE", -- 1 = importedKeyRestrict
22+
1 AS "DELETE_RULE", -- 1 = importedKeyRestrict
23+
CONSTRAINTS.CONSTRAINT_NAME AS "FK_NAME", CONSTRAINTS.UNIQUE_CONSTRAINT_NAME AS "PK_NAME",
24+
7 AS "DEFERRABILITY" -- 7 = importedKeyNotDeferrable
25+
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS CONSTRAINTS
26+
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
27+
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
28+
WHERE UPPER(PARENT.TABLE_CATALOG) LIKE ?
29+
AND UPPER(PARENT.TABLE_SCHEMA) LIKE ?
30+
AND UPPER(PARENT.TABLE_NAME) LIKE ?
31+
ORDER BY CHILD.TABLE_CATALOG, CHILD.TABLE_SCHEMA, CHILD.TABLE_NAME, CHILD.ORDINAL_POSITION
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
SELECT PARENT.TABLE_CATALOG AS "PKTABLE_CAT", PARENT.TABLE_SCHEMA AS "PKTABLE_SCHEM", PARENT.TABLE_NAME AS "PKTABLE_NAME",
18+
PARENT.COLUMN_NAME AS "PKCOLUMN_NAME", CHILD.TABLE_CATALOG AS "FKTABLE_CAT", CHILD.TABLE_SCHEMA AS "FKTABLE_SCHEM",
19+
CHILD.TABLE_NAME AS "FKTABLE_NAME", CHILD.COLUMN_NAME AS "FKCOLUMN_NAME",
20+
CHILD.ORDINAL_POSITION AS "KEY_SEQ",
21+
1 AS "UPDATE_RULE", -- 1 = importedKeyRestrict
22+
1 AS "DELETE_RULE", -- 1 = importedKeyRestrict
23+
CONSTRAINTS.CONSTRAINT_NAME AS "FK_NAME", CONSTRAINTS.UNIQUE_CONSTRAINT_NAME AS "PK_NAME",
24+
7 AS "DEFERRABILITY" -- 7 = importedKeyNotDeferrable
25+
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS CONSTRAINTS
26+
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
27+
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
28+
WHERE UPPER(CHILD.TABLE_CATALOG) LIKE ?
29+
AND UPPER(CHILD.TABLE_SCHEMA) LIKE ?
30+
AND UPPER(CHILD.TABLE_NAME) LIKE ?
31+
ORDER BY PARENT.TABLE_CATALOG, PARENT.TABLE_SCHEMA, PARENT.TABLE_NAME, CHILD.ORDINAL_POSITION
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
SELECT IDX.TABLE_CATALOG AS "TABLE_CAT", IDX.TABLE_SCHEMA AS "TABLE_SCHEM", IDX.TABLE_NAME AS "TABLE_NAME",
18+
CASE WHEN IS_UNIQUE='YES' THEN FALSE ELSE TRUE END AS "NON_UNIQUE",
19+
IDX.TABLE_CATALOG AS "INDEX_QUALIFIER", IDX.INDEX_NAME AS "INDEX_NAME",
20+
2 AS "TYPE",
21+
ORDINAL_POSITION AS "ORDINAL_POSITION", COLUMN_NAME AS "COLUMN_NAME", SUBSTR(COLUMN_ORDERING, 1, 1) AS "ASC_OR_DESC",
22+
-1 AS "CARDINALITY", -- Not supported
23+
-1 AS "PAGES", -- Not supported
24+
NULL AS "FILTER_CONDITION"
25+
FROM INFORMATION_SCHEMA.INDEXES IDX
26+
INNER JOIN INFORMATION_SCHEMA.INDEX_COLUMNS COL
27+
ON IDX.TABLE_CATALOG=COL.TABLE_CATALOG
28+
AND IDX.TABLE_SCHEMA=COL.TABLE_SCHEMA
29+
AND IDX.TABLE_NAME=COL.TABLE_NAME
30+
AND IDX.INDEX_NAME=COL.INDEX_NAME
31+
WHERE UPPER(IDX.TABLE_CATALOG) LIKE ?
32+
AND UPPER(IDX.TABLE_SCHEMA) LIKE ?
33+
AND UPPER(IDX.TABLE_NAME) LIKE ?
34+
AND UPPER(IDX.INDEX_NAME) LIKE ?
35+
AND UPPER(IS_UNIQUE) LIKE ?
36+
ORDER BY IDX.TABLE_NAME, IS_UNIQUE DESC, IDX.INDEX_NAME, CASE WHEN ORDINAL_POSITION IS NULL THEN 0 ELSE ORDINAL_POSITION END
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
SELECT IDX.TABLE_CATALOG AS "TABLE_CAT", IDX.TABLE_SCHEMA AS "TABLE_SCHEM", IDX.TABLE_NAME AS "TABLE_NAME",
18+
COLS.COLUMN_NAME AS "COLUMN_NAME", ORDINAL_POSITION AS "KEY_SEQ", IDX.INDEX_NAME AS "PK_NAME"
19+
FROM INFORMATION_SCHEMA.INDEXES IDX
20+
INNER JOIN INFORMATION_SCHEMA.INDEX_COLUMNS COLS
21+
ON IDX.TABLE_CATALOG=COLS.TABLE_CATALOG
22+
AND IDX.TABLE_SCHEMA=COLS.TABLE_SCHEMA
23+
AND IDX.TABLE_NAME=COLS.TABLE_NAME
24+
AND IDX.INDEX_NAME=COLS.INDEX_NAME
25+
WHERE IDX.INDEX_TYPE='PRIMARY_KEY'
26+
AND UPPER(IDX.TABLE_CATALOG) LIKE ?
27+
AND UPPER(IDX.TABLE_SCHEMA) LIKE ?
28+
AND UPPER(IDX.TABLE_NAME) LIKE ?
29+
ORDER BY COLS.ORDINAL_POSITION

0 commit comments

Comments
 (0)