Skip to content

Commit

Permalink
fix: create specific metadata queries for PG (#759)
Browse files Browse the repository at this point in the history
* 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
olavloite and gcf-owl-bot[bot] authored Feb 24, 2022
1 parent 6fca6b3 commit caffda0
Show file tree
Hide file tree
Showing 21 changed files with 1,186 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.auth.Credentials;
import com.google.auth.ServiceAccountSigner;
import com.google.auth.oauth2.UserCredentials;
import com.google.cloud.spanner.Dialect;
import com.google.cloud.spanner.ResultSets;
import com.google.cloud.spanner.Struct;
import com.google.cloud.spanner.Type;
Expand Down Expand Up @@ -48,8 +49,16 @@ class JdbcDatabaseMetaData extends AbstractJdbcWrapper implements DatabaseMetaDa
private static final String PRODUCT_NAME = "Google Cloud Spanner";

@VisibleForTesting
static String readSqlFromFile(String filename) {
InputStream in = JdbcDatabaseMetaData.class.getResourceAsStream(filename);
static String readSqlFromFile(String filename, Dialect dialect) {
InputStream in;
switch (dialect) {
case POSTGRESQL:
in = JdbcDatabaseMetaData.class.getResourceAsStream("postgresql/" + filename);
break;
case GOOGLE_STANDARD_SQL:
default:
in = JdbcDatabaseMetaData.class.getResourceAsStream(filename);
}
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder builder = new StringBuilder();
try (Scanner scanner = new Scanner(reader)) {
Expand Down Expand Up @@ -743,7 +752,7 @@ private JdbcPreparedStatement prepareStatementReplaceNullWithAnyString(
public ResultSet getTables(
String catalog, String schemaPattern, String tableNamePattern, String[] types)
throws SQLException {
String sql = readSqlFromFile("DatabaseMetaData_GetTables.sql");
String sql = readSqlFromFile("DatabaseMetaData_GetTables.sql", connection.getDialect());
String type1;
String type2;
if (types == null || types.length == 0) {
Expand Down Expand Up @@ -789,7 +798,7 @@ public ResultSet getTableTypes() {
public ResultSet getColumns(
String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern)
throws SQLException {
String sql = readSqlFromFile("DatabaseMetaData_GetColumns.sql");
String sql = readSqlFromFile("DatabaseMetaData_GetColumns.sql", connection.getDialect());
JdbcPreparedStatement statement =
prepareStatementReplaceNullWithAnyString(
sql, catalog, schemaPattern, tableNamePattern, columnNamePattern);
Expand Down Expand Up @@ -858,7 +867,7 @@ private ResultSet getEmptyColumnsResultSet() {
@Override
public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException {
JdbcPreconditions.checkArgument(table != null, "table may not be null");
String sql = readSqlFromFile("DatabaseMetaData_GetPrimaryKeys.sql");
String sql = readSqlFromFile("DatabaseMetaData_GetPrimaryKeys.sql", connection.getDialect());
JdbcPreparedStatement statement =
prepareStatementReplaceNullWithAnyString(sql, catalog, schema, table);
return statement.executeQueryWithOptions(InternalMetadataQuery.INSTANCE);
Expand All @@ -868,7 +877,7 @@ public ResultSet getPrimaryKeys(String catalog, String schema, String table) thr
public ResultSet getImportedKeys(String catalog, String schema, String table)
throws SQLException {
JdbcPreconditions.checkArgument(table != null, "table may not be null");
String sql = readSqlFromFile("DatabaseMetaData_GetImportedKeys.sql");
String sql = readSqlFromFile("DatabaseMetaData_GetImportedKeys.sql", connection.getDialect());
JdbcPreparedStatement statement =
prepareStatementReplaceNullWithAnyString(sql, catalog, schema, table);
return statement.executeQueryWithOptions(InternalMetadataQuery.INSTANCE);
Expand All @@ -878,7 +887,7 @@ public ResultSet getImportedKeys(String catalog, String schema, String table)
public ResultSet getExportedKeys(String catalog, String schema, String table)
throws SQLException {
JdbcPreconditions.checkArgument(table != null, "table may not be null");
String sql = readSqlFromFile("DatabaseMetaData_GetExportedKeys.sql");
String sql = readSqlFromFile("DatabaseMetaData_GetExportedKeys.sql", connection.getDialect());
JdbcPreparedStatement statement =
prepareStatementReplaceNullWithAnyString(sql, catalog, schema, table);
return statement.executeQueryWithOptions(InternalMetadataQuery.INSTANCE);
Expand All @@ -893,7 +902,8 @@ public ResultSet getCrossReference(
String foreignSchema,
String foreignTable)
throws SQLException {
String sql = readSqlFromFile("DatabaseMetaData_GetCrossReferences.sql");
String sql =
readSqlFromFile("DatabaseMetaData_GetCrossReferences.sql", connection.getDialect());
JdbcPreparedStatement statement =
prepareStatementReplaceNullWithAnyString(
sql,
Expand Down Expand Up @@ -1251,7 +1261,7 @@ public ResultSet getIndexInfo(String catalog, String schema, String indexName)
private ResultSet getIndexInfo(
String catalog, String schema, String table, String indexName, boolean unique)
throws SQLException {
String sql = readSqlFromFile("DatabaseMetaData_GetIndexInfo.sql");
String sql = readSqlFromFile("DatabaseMetaData_GetIndexInfo.sql", connection.getDialect());
JdbcPreparedStatement statement =
prepareStatementReplaceNullWithAnyString(
sql, catalog, schema, table, indexName, unique ? "YES" : "%");
Expand Down Expand Up @@ -1467,7 +1477,7 @@ public RowIdLifetime getRowIdLifetime() {

@Override
public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException {
String sql = readSqlFromFile("DatabaseMetaData_GetSchemas.sql");
String sql = readSqlFromFile("DatabaseMetaData_GetSchemas.sql", connection.getDialect());
JdbcPreparedStatement statement =
prepareStatementReplaceNullWithAnyString(sql, catalog, schemaPattern);
return statement.executeQueryWithOptions(InternalMetadataQuery.INSTANCE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*GSQL*/
/*
* Copyright 2019 Google LLC
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*GSQL*/
/*
* Copyright 2019 Google LLC
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*GSQL*/
/*
* Copyright 2019 Google LLC
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*GSQL*/
/*
* Copyright 2019 Google LLC
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*GSQL*/
/*
* Copyright 2019 Google LLC
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*GSQL*/
/*
* Copyright 2019 Google LLC
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*GSQL*/
/*
* Copyright 2019 Google LLC
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*GSQL*/
/*
* Copyright 2019 Google LLC
*
Expand Down
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
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
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
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
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
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
Loading

0 comments on commit caffda0

Please sign in to comment.