All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.cloud.spanner.jdbc.DatabaseMetaData_GetColumns.sql Maven / Gradle / Ivy

There is a newer version: 2.25.2
Show newest version
/*
 * Copyright 2019 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, COLUMN_NAME,
  CASE
    WHEN SPANNER_TYPE LIKE 'ARRAY%' THEN 2003
    WHEN SPANNER_TYPE = 'BOOL' THEN 16
    WHEN SPANNER_TYPE LIKE 'BYTES%' THEN -2
    WHEN SPANNER_TYPE = 'DATE' THEN 91
    WHEN SPANNER_TYPE = 'FLOAT64' THEN 8
    WHEN SPANNER_TYPE = 'FLOAT32' THEN 7
    WHEN SPANNER_TYPE = 'INT64' THEN -5
    WHEN SPANNER_TYPE = 'NUMERIC' THEN 2
    WHEN SPANNER_TYPE LIKE 'STRING%' THEN -9
    WHEN SPANNER_TYPE = 'JSON' THEN -9
    WHEN SPANNER_TYPE = 'TIMESTAMP' THEN 93
  END AS DATA_TYPE,
  SPANNER_TYPE AS TYPE_NAME,
  CASE
    WHEN STRPOS(SPANNER_TYPE, '(')=0 THEN
      CASE
        WHEN SPANNER_TYPE = 'INT64' OR SPANNER_TYPE = 'ARRAY' THEN 19
        WHEN SPANNER_TYPE = 'NUMERIC' OR SPANNER_TYPE = 'ARRAY' THEN 15
        WHEN SPANNER_TYPE = 'FLOAT64' OR SPANNER_TYPE = 'ARRAY' THEN 15
        WHEN SPANNER_TYPE = 'FLOAT32' OR SPANNER_TYPE = 'ARRAY' THEN 15
        WHEN SPANNER_TYPE = 'BOOL' OR SPANNER_TYPE = 'ARRAY' THEN NULL
        WHEN SPANNER_TYPE = 'DATE' OR SPANNER_TYPE = 'ARRAY' THEN 10
        WHEN SPANNER_TYPE = 'TIMESTAMP' OR SPANNER_TYPE = 'ARRAY' THEN 35
        WHEN SPANNER_TYPE = 'JSON' OR SPANNER_TYPE = 'ARRAY' THEN 2621440
        ELSE 0
      END
    ELSE CAST(REPLACE(SUBSTR(SPANNER_TYPE, STRPOS(SPANNER_TYPE, '(')+1, STRPOS(SPANNER_TYPE, ')')-STRPOS(SPANNER_TYPE, '(')-1), 'MAX', CASE WHEN UPPER(SPANNER_TYPE) LIKE '%STRING%' THEN '2621440' ELSE '10485760' END) AS INT64)
  END AS COLUMN_SIZE,
  0 AS BUFFER_LENGTH,
  CASE
    WHEN SPANNER_TYPE LIKE '%FLOAT64%' THEN 16
    WHEN SPANNER_TYPE LIKE '%FLOAT32%' THEN 16
    ELSE NULL
  END AS DECIMAL_DIGITS,
  CASE
    WHEN SPANNER_TYPE LIKE '%INT64%' THEN 10
    WHEN SPANNER_TYPE LIKE '%NUMERIC%' THEN 10
    WHEN SPANNER_TYPE LIKE '%FLOAT64%' THEN 2
    WHEN SPANNER_TYPE LIKE '%FLOAT32%' 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,
  CASE
    WHEN (SPANNER_TYPE LIKE 'STRING%' OR SPANNER_TYPE LIKE 'ARRAY




© 2015 - 2025 Weber Informatics LLC | Privacy Policy