in src/odbc/rsodbc/rscatalog.cpp [3440:3988]
static void buildLocalSchemaColumnsQuery(char *pszCatalogQuery,
RS_STMT_INFO *pStmt,
SQLCHAR *pCatalogName,
SQLSMALLINT cbCatalogName,
SQLCHAR *pSchemaName,
SQLSMALLINT cbSchemaName,
SQLCHAR *pTableName,
SQLSMALLINT cbTableName,
SQLCHAR *pColumnName,
SQLSMALLINT cbColumnName)
{
std::string result = "";
char catalogFilter[MAX_LARGE_TEMP_BUF_LEN];
char filterClause[MAX_CATALOG_QUERY_FILTER_LEN];
getCatalogFilterCondition(catalogFilter, MAX_LARGE_TEMP_BUF_LEN, pStmt, (char *)pCatalogName, cbCatalogName,
TRUE, NULL);
result.append("SELECT * FROM ( ");
result.append("SELECT current_database() AS TABLE_CAT, ");
result.append("n.nspname AS TABLE_SCHEM, ");
result.append("c.relname as TABLE_NAME , ");
result.append("a.attname as COLUMN_NAME, ");
result.append("CAST(case typname ");
result.append("when 'text' THEN 12 ");
result.append("when 'bit' THEN -7 ");
result.append("when 'bool' THEN -7 ");
result.append("when 'boolean' THEN -7 ");
result.append("when 'varchar' THEN 12 ");
result.append("when 'character varying' THEN 12 ");
result.append("when 'char' THEN 1 ");
result.append("when '\"char\"' THEN 1 ");
result.append("when 'character' THEN 1 ");
result.append("when 'nchar' THEN 12 ");
result.append("when 'bpchar' THEN 1 ");
result.append("when 'nvarchar' THEN 12 ");
result.append("when 'date' THEN 91 ");
result.append("when 'time' THEN 92 ");
result.append("when 'time without time zone' THEN 92 ");
result.append("when 'timetz' THEN 92 ");
result.append("when 'time with time zone' THEN 92 ");
result.append("when 'timestamp' THEN 93 ");
result.append("when 'timestamp without time zone' THEN 93 ");
result.append("when 'timestamptz' THEN 93 ");
result.append("when 'timestamp with time zone' THEN 93 ");
result.append("when 'smallint' THEN 5 ");
result.append("when 'int2' THEN 5 ");
result.append("when 'integer' THEN 4 ");
result.append("when 'int' THEN 4 ");
result.append("when 'int4' THEN 4 ");
result.append("when 'bigint' THEN -5 ");
result.append("when 'int8' THEN -5 ");
result.append("when 'decimal' THEN 3 ");
result.append("when 'real' THEN 7 ");
result.append("when 'float4' THEN 7 ");
result.append("when 'double precision' THEN 8 ");
result.append("when 'float8' THEN 8 ");
result.append("when 'float' THEN 6 ");
result.append("when 'numeric' THEN 2 ");
result.append("when '_float4' THEN 2003 ");
result.append("when '_aclitem' THEN 2003 ");
result.append("when '_text' THEN 2003 ");
result.append("when 'bytea' THEN -2 ");
result.append("when 'oid' THEN -5 ");
result.append("when 'name' THEN 12 ");
result.append("when '_int4' THEN 2003 ");
result.append("when '_int2' THEN 2003 ");
result.append("when 'ARRAY' THEN 2003 ");
result.append("when 'geometry' THEN -4 ");
result.append("when 'super' THEN -1 ");
result.append("when 'varbyte' THEN -4 ");
result.append("when 'geography' THEN -4 ");
result.append("when 'intervaly2m' THEN 107 ");
result.append("when 'intervald2s' THEN 110 ");
result.append("else 0 END as SMALLINT) AS DATA_TYPE, ");
result.append("t.typname as TYPE_NAME, ");
result.append("case typname ");
result.append("when 'int4' THEN 10 ");
result.append("when 'bit' THEN 1 ");
result.append("when 'bool' THEN 1 ");
result.append("when 'varchar' THEN atttypmod -4 ");
result.append("when 'character varying' THEN atttypmod -4 ");
result.append("when 'char' THEN atttypmod -4 ");
result.append("when 'character' THEN atttypmod -4 ");
result.append("when 'nchar' THEN atttypmod -4 ");
result.append("when 'bpchar' THEN atttypmod -4 ");
result.append("when 'nvarchar' THEN atttypmod -4 ");
result.append("when 'date' THEN 13 ");
result.append("when 'time' THEN 15 ");
result.append("when 'time without time zone' THEN 15 ");
result.append("when 'timetz' THEN 21 ");
result.append("when 'time with time zone' THEN 21 ");
result.append("when 'timestamp' THEN 29 ");
result.append("when 'timestamp without time zone' THEN 29 ");
result.append("when 'timestamptz' THEN 35 ");
result.append("when 'timestamp with time zone' THEN 35 ");
result.append("when 'smallint' THEN 5 ");
result.append("when 'int2' THEN 5 ");
result.append("when 'integer' THEN 10 ");
result.append("when 'int' THEN 10 ");
result.append("when 'int4' THEN 10 ");
result.append("when 'bigint' THEN 19 ");
result.append("when 'int8' THEN 19 ");
result.append("when 'decimal' then (atttypmod - 4) >> 16 ");
result.append("when 'real' THEN 8 ");
result.append("when 'float4' THEN 8 ");
result.append("when 'double precision' THEN 17 ");
result.append("when 'float8' THEN 17 ");
result.append("when 'float' THEN 17 ");
result.append("when 'numeric' THEN (atttypmod - 4) >> 16 ");
result.append("when '_float4' THEN 8 ");
result.append("when 'oid' THEN 10 ");
result.append("when '_int4' THEN 10 ");
result.append("when '_int2' THEN 5 ");
result.append("when 'geometry' THEN NULL ");
result.append("when 'super' THEN NULL ");
result.append("when 'varbyte' THEN NULL ");
result.append("when 'geography' THEN NULL ");
result.append("when 'intervaly2m' THEN 32 ");
result.append("when 'intervald2s' THEN 64 ");
// if (connSettings.m_unknownLength == null)
{
result.append("else 2147483647 end as COLUMN_SIZE , ");
}
/* else
{
result.append("else ");
result.append(connSettings.m_unknownLength);
result.append(" end as COLUMN_SIZE , ");
} */
result.append("CAST(NULL as INTEGER) as BUFFER_LENGTH , ");
result.append("CAST(case typname ");
result.append("when 'float4' then 8 ");
result.append("when 'float8' then 17 ");
result.append("when 'numeric' then (atttypmod - 4) & 65535 ");
result.append("when 'time without time zone' then 6 ");
result.append("when 'timetz' then 6 ");
result.append("when 'time with time zone' then 6 ");
result.append("when 'timestamp without time zone' then 6 ");
result.append("when 'timestamp' then 6 ");
result.append("when 'geometry' then NULL ");
result.append("when 'super' then NULL ");
result.append("when 'varbyte' then NULL ");
result.append("when 'geography' then NULL ");
result.append("when 'intervaly2m' THEN 0 ");
result.append("when 'intervald2s' THEN 6 ");
result.append("else 0 end AS SMALLINT) as DECIMAL_DIGITS, ");
result.append("CAST(case typname ");
result.append("when 'varbyte' then 2 ");
result.append("when 'geography' then 2 ");
result.append("when 'varchar' THEN 0 ");
result.append("when 'character varying' THEN 0 ");
result.append("when 'char' THEN 0 ");
result.append("when 'character' THEN 0 ");
result.append("when 'nchar' THEN 0 ");
result.append("when 'bpchar' THEN 0 ");
result.append("when 'nvarchar' THEN 0 ");
result.append("else 10 end AS SMALLINT) as NUM_PREC_RADIX, ");
result.append("CAST(case a.attnotnull OR (t.typtype = 'd' AND t.typnotnull) ");
result.append("when 'false' then 1 ");
result.append("when NULL then 2 ");
result.append("else 0 end AS SMALLINT) AS NULLABLE , ");
result.append("dsc.description as REMARKS , ");
result.append("pg_catalog.pg_get_expr(def.adbin, def.adrelid) AS COLUMN_DEF, ");
result.append("CAST(case typname ");
result.append("when 'text' THEN 12 ");
result.append("when 'bit' THEN -7 ");
result.append("when 'bool' THEN -7 ");
result.append("when 'boolean' THEN -7 ");
result.append("when 'varchar' THEN 12 ");
result.append("when 'character varying' THEN 12 ");
result.append("when '\"char\"' THEN 1 ");
result.append("when 'char' THEN 1 ");
result.append("when 'character' THEN 1 ");
result.append("when 'nchar' THEN 1 ");
result.append("when 'bpchar' THEN 1 ");
result.append("when 'nvarchar' THEN 12 ");
result.append("when 'date' THEN 9 ");
result.append("when 'time' THEN 9 ");
result.append("when 'time without time zone' THEN 9 ");
result.append("when 'timetz' THEN 9 ");
result.append("when 'time with time zone' THEN 9 ");
result.append("when 'timestamp with time zone' THEN 9 ");
result.append("when 'timestamp' THEN 9 ");
result.append("when 'timestamp without time zone' THEN 9 ");
result.append("when 'smallint' THEN 5 ");
result.append("when 'int2' THEN 5 ");
result.append("when 'integer' THEN 4 ");
result.append("when 'int' THEN 4 ");
result.append("when 'int4' THEN 4 ");
result.append("when 'bigint' THEN -5 ");
result.append("when 'int8' THEN -5 ");
result.append("when 'decimal' THEN 3 ");
result.append("when 'real' THEN 7 ");
result.append("when 'float4' THEN 7 ");
result.append("when 'double precision' THEN 8 ");
result.append("when 'float8' THEN 8 ");
result.append("when 'float' THEN 6 ");
result.append("when 'numeric' THEN 2 ");
result.append("when '_float4' THEN 2003 ");
result.append("when 'timestamptz' THEN 9 ");
result.append("when 'timestamp with time zone' THEN 9 ");
result.append("when '_aclitem' THEN 2003 ");
result.append("when '_text' THEN 2003 ");
result.append("when 'bytea' THEN -2 ");
result.append("when 'oid' THEN -5 ");
result.append("when 'name' THEN 12 ");
result.append("when '_int4' THEN 2003 ");
result.append("when '_int2' THEN 2003 ");
result.append("when 'ARRAY' THEN 2003 ");
result.append("when 'geometry' THEN -4 ");
result.append("when 'super' THEN -1 ");
result.append("when 'varbyte' THEN -4 ");
result.append("when 'geography' THEN -4 ");
result.append("when 'intervaly2m' THEN 107 ");
result.append("when 'intervald2s' THEN 110 ");
result.append("else 0 END as SMALLINT) AS SQL_DATA_TYPE, ");
result.append("CAST(case typname ");
result.append("when 'date' THEN 1 ");
result.append("when 'time' THEN 2 ");
result.append("when 'time without time zone' THEN 2 ");
result.append("when 'timetz' THEN 2 ");
result.append("when 'time with time zone' THEN 2 ");
result.append("when 'timestamp with time zone' THEN 3 ");
result.append("when 'timestamptz' THEN 3 ");
result.append("when 'timestamp' THEN 3 ");
result.append("when 'timestamp without time zone' THEN 3 ");
result.append("else NULL END AS SMALLINT) as SQL_DATETIME_SUB, ");
result.append("case typname ");
result.append("when 'int4' THEN 10 ");
result.append("when 'bit' THEN 1 ");
result.append("when 'bool' THEN 1 ");
result.append("when 'varchar' THEN atttypmod -4 ");
result.append("when 'character varying' THEN atttypmod -4 ");
result.append("when 'char' THEN atttypmod -4 ");
result.append("when 'character' THEN atttypmod -4 ");
result.append("when 'nchar' THEN atttypmod -4 ");
result.append("when 'bpchar' THEN atttypmod -4 ");
result.append("when 'nvarchar' THEN atttypmod -4 ");
result.append("when 'date' THEN 13 ");
result.append("when 'time' THEN 15 ");
result.append("when 'time without time zone' THEN 15 ");
result.append("when 'timetz' THEN 21 ");
result.append("when 'time with time zone' THEN 21 ");
result.append("when 'timestamp' THEN 29 ");
result.append("when 'timestamp without time zone' THEN 29 ");
result.append("when 'timestamptz' THEN 35 ");
result.append("when 'timestamp with time zone' THEN 35 ");
result.append("when 'smallint' THEN 5 ");
result.append("when 'int2' THEN 5 ");
result.append("when 'integer' THEN 10 ");
result.append("when 'int' THEN 10 ");
result.append("when 'int4' THEN 10 ");
result.append("when 'bigint' THEN 19 ");
result.append("when 'int8' THEN 19 ");
result.append("when 'decimal' then ((atttypmod - 4) >> 16) & 65535 ");
result.append("when 'real' THEN 8 ");
result.append("when 'float4' THEN 8 ");
result.append("when 'double precision' THEN 17 ");
result.append("when 'float8' THEN 17 ");
result.append("when 'float' THEN 17 ");
result.append("when 'numeric' THEN ((atttypmod - 4) >> 16) & 65535 ");
result.append("when '_float4' THEN 8 ");
result.append("when 'oid' THEN 10 ");
result.append("when '_int4' THEN 10 ");
result.append("when '_int2' THEN 5 ");
result.append("when 'geometry' THEN NULL ");
result.append("when 'super' THEN NULL ");
result.append("when 'varbyte' THEN NULL ");
result.append("when 'geography' THEN NULL ");
result.append("when 'intervaly2m' THEN 32 ");
result.append("when 'intervald2s' THEN 64 ");
// if (connSettings.m_unknownLength == null)
// {
result.append("else 2147483647 end as CHAR_OCTET_LENGTH , ");
// }
/* else
{
result.append("else ");
result.append(connSettings.m_unknownLength);
result.append(" end as CHAR_OCTET_LENGTH , ");
} */
result.append("a.attnum AS ORDINAL_POSITION, ");
result.append("case a.attnotnull OR (t.typtype = 'd' AND t.typnotnull) ");
result.append("when 'false' then 'YES' ");
result.append("when NULL then '' ");
result.append("else 'NO' end AS IS_NULLABLE ");
/* result.append("null as SCOPE_CATALOG ");
result.append("null as SCOPE_SCHEMA , ");
result.append("null as SCOPE_TABLE, ");
result.append("t.typbasetype AS SOURCE_DATA_TYPE , ");
result.append("CASE WHEN left(pg_catalog.pg_get_expr(def.adbin, def.adrelid), 16) = 'default_identity' THEN 'YES' ");
result.append("ELSE 'NO' END AS IS_AUTOINCREMENT, ");
result.append("IS_AUTOINCREMENT AS IS_GENERATEDCOLUMN ");
*/
result.append("FROM pg_catalog.pg_namespace n JOIN pg_catalog.pg_class c ON (c.relnamespace = n.oid) ");
result.append("JOIN pg_catalog.pg_attribute a ON (a.attrelid=c.oid) ");
result.append("JOIN pg_catalog.pg_type t ON (a.atttypid = t.oid) ");
result.append("LEFT JOIN pg_catalog.pg_attrdef def ON (a.attrelid=def.adrelid AND a.attnum = def.adnum) ");
result.append("LEFT JOIN pg_catalog.pg_description dsc ON (c.oid=dsc.objoid AND a.attnum = dsc.objsubid) ");
result.append("LEFT JOIN pg_catalog.pg_class dc ON (dc.oid=dsc.classoid AND dc.relname='pg_class') ");
result.append("LEFT JOIN pg_catalog.pg_namespace dn ON (dc.relnamespace=dn.oid AND dn.nspname='pg_catalog') ");
result.append("WHERE a.attnum > 0 AND NOT a.attisdropped ");
result.append(catalogFilter);
filterClause[0] = '\0';
addLikeOrEqualFilterCondition(pStmt, filterClause, "n.nspname", (char *)pSchemaName, cbSchemaName);
addLikeOrEqualFilterCondition(pStmt, filterClause, "c.relname", (char *)pTableName, cbTableName);
addLikeOrEqualFilterCondition(pStmt, filterClause, "attname", (char *)pColumnName, cbColumnName);
result.append(filterClause);
result.append(" ORDER BY TABLE_SCHEM,c.relname,attnum ) ");
// This part uses redshift method PG_GET_LATE_BINDING_VIEW_COLS() to
// get the column list for late binding view.
result.append(" UNION ALL ");
result.append("SELECT current_database()::VARCHAR(128) AS TABLE_CAT, ");
result.append("schemaname::varchar(128) AS table_schem, ");
result.append("tablename::varchar(128) AS table_name, ");
result.append("columnname::varchar(128) AS column_name, ");
result.append("CAST(CASE columntype_rep ");
result.append("WHEN 'text' THEN 12 ");
result.append("WHEN 'bit' THEN -7 ");
result.append("WHEN 'bool' THEN -7 ");
result.append("WHEN 'boolean' THEN -7 ");
result.append("WHEN 'varchar' THEN 12 ");
result.append("WHEN 'character varying' THEN 12 ");
result.append("WHEN 'char' THEN 1 ");
result.append("WHEN 'character' THEN 1 ");
result.append("WHEN 'nchar' THEN 1 ");
result.append("WHEN 'bpchar' THEN 1 ");
result.append("WHEN 'nvarchar' THEN 12 ");
result.append("WHEN '\"char\"' THEN 1 ");
result.append("WHEN 'date' THEN 91 ");
result.append("when 'time' THEN 92 ");
result.append("when 'time without time zone' THEN 92 ");
result.append("when 'timetz' THEN 92 ");
result.append("when 'time with time zone' THEN 92 ");
result.append("WHEN 'timestamp' THEN 93 ");
result.append("WHEN 'timestamp without time zone' THEN 93 ");
result.append("when 'timestamptz' THEN 93 ");
result.append("WHEN 'timestamp with time zone' THEN 93 ");
result.append("WHEN 'smallint' THEN 5 ");
result.append("WHEN 'int2' THEN 5 ");
result.append("WHEN 'integer' THEN 4 ");
result.append("WHEN 'int' THEN 4 ");
result.append("WHEN 'int4' THEN 4 ");
result.append("WHEN 'bigint' THEN -5 ");
result.append("WHEN 'int8' THEN -5 ");
result.append("WHEN 'decimal' THEN 3 ");
result.append("WHEN 'real' THEN 7 ");
result.append("WHEN 'float4' THEN 7 ");
result.append("WHEN 'double precision' THEN 8 ");
result.append("WHEN 'float8' THEN 8 ");
result.append("WHEN 'float' THEN 6 ");
result.append("WHEN 'numeric' THEN 2 ");
result.append("WHEN 'timestamptz' THEN 93 ");
result.append("WHEN 'bytea' THEN -2 ");
result.append("WHEN 'oid' THEN -5 ");
result.append("WHEN 'name' THEN 12 ");
result.append("WHEN 'ARRAY' THEN 2003 ");
result.append("WHEN 'geometry' THEN -4 ");
result.append("WHEN 'super' THEN -1 ");
result.append("WHEN 'varbyte' THEN -4 ");
result.append("WHEN 'geography' THEN -4 ");
result.append("when 'intervaly2m' THEN 107 ");
result.append("when 'intervald2s' THEN 110 ");
result.append("ELSE 0 END AS SMALLINT) AS DATA_TYPE, ");
result.append("COALESCE(NULL,CASE columntype WHEN 'boolean' THEN 'bool' ");
result.append("WHEN 'character varying' THEN 'varchar' ");
result.append("WHEN '\"char\"' THEN 'char' ");
result.append("WHEN 'smallint' THEN 'int2' ");
result.append("WHEN 'integer' THEN 'int4'");
result.append("WHEN 'bigint' THEN 'int8' ");
result.append("WHEN 'real' THEN 'float4' ");
result.append("WHEN 'double precision' THEN 'float8' ");
result.append("WHEN 'time without time zone' THEN 'time' ");
result.append("WHEN 'time with time zone' THEN 'timetz' ");
result.append("WHEN 'timestamp without time zone' THEN 'timestamp' ");
result.append("WHEN 'timestamp with time zone' THEN 'timestamptz' ");
result.append("ELSE columntype END) AS TYPE_NAME, ");
result.append("CASE columntype_rep ");
result.append("WHEN 'int4' THEN 10 ");
result.append("WHEN 'bit' THEN 1 ");
result.append("WHEN 'bool' THEN 1");
result.append("WHEN 'boolean' THEN 1");
result.append("WHEN 'varchar' THEN isnull(nullif(regexp_substr (columntype,'[0-9]+',7),''),'0')::INTEGER ");
result.append("WHEN 'character varying' THEN isnull(nullif(regexp_substr (columntype,'[0-9]+',7),''),'0')::INTEGER ");
result.append("WHEN 'char' THEN isnull(nullif(regexp_substr (columntype,'[0-9]+',4),''),'0')::INTEGER ");
result.append("WHEN 'character' THEN isnull(nullif(regexp_substr (columntype,'[0-9]+',4),''),'0')::INTEGER ");
result.append("WHEN 'nchar' THEN isnull(nullif(regexp_substr (columntype,'[0-9]+',7),''),'0')::INTEGER ");
result.append("WHEN 'bpchar' THEN isnull(nullif(regexp_substr (columntype,'[0-9]+',7),''),'0')::INTEGER ");
result.append("WHEN 'nvarchar' THEN isnull(nullif(regexp_substr (columntype,'[0-9]+',7),''),'0')::INTEGER ");
result.append("WHEN 'date' THEN 13 ");
result.append("WHEN 'time' THEN 15 ");
result.append("WHEN 'time without time zone' THEN 15 ");
result.append("WHEN 'timetz' THEN 21 ");
result.append("WHEN 'timestamp' THEN 29 ");
result.append("WHEN 'timestamp without time zone' THEN 29 ");
result.append("WHEN 'time with time zone' THEN 21 ");
result.append("WHEN 'timestamptz' THEN 35 ");
result.append("WHEN 'timestamp with time zone' THEN 35 ");
result.append("WHEN 'smallint' THEN 5 ");
result.append("WHEN 'int2' THEN 5 ");
result.append("WHEN 'integer' THEN 10 ");
result.append("WHEN 'int' THEN 10 ");
result.append("WHEN 'int4' THEN 10 ");
result.append("WHEN 'bigint' THEN 19 ");
result.append("WHEN 'int8' THEN 19 ");
result.append("WHEN 'decimal' THEN isnull(nullif(regexp_substr (columntype,'[0-9]+',7),''),'0')::INTEGER ");
result.append("WHEN 'real' THEN 8 ");
result.append("WHEN 'float4' THEN 8 ");
result.append("WHEN 'double precision' THEN 17 ");
result.append("WHEN 'float8' THEN 17 ");
result.append("WHEN 'float' THEN 17");
result.append("WHEN 'numeric' THEN isnull(nullif(regexp_substr (columntype,'[0-9]+',7),''),'0')::INTEGER ");
result.append("WHEN '_float4' THEN 8 ");
result.append("WHEN 'oid' THEN 10 ");
result.append("WHEN '_int4' THEN 10 ");
result.append("WHEN '_int2' THEN 5 ");
result.append("WHEN 'geometry' THEN NULL ");
result.append("WHEN 'super' THEN NULL ");
result.append("WHEN 'varbyte' THEN NULL ");
result.append("WHEN 'geography' THEN NULL ");
result.append("WHEN 'intervaly2m' THEN 32 ");
result.append("WHEN 'intervald2s' THEN 64 ");
result.append("ELSE 2147483647 END AS COLUMN_SIZE, ");
result.append("CAST(NULL as INTEGER) AS BUFFER_LENGTH, ");
result.append("CAST(CASE REGEXP_REPLACE(columntype,'[()0-9,]') ");
result.append("WHEN 'real' THEN 8 ");
result.append("WHEN 'float4' THEN 8 ");
result.append("WHEN 'double precision' THEN 17 ");
result.append("WHEN 'float8' THEN 17 ");
result.append("WHEN 'timestamp' THEN 6 ");
result.append("WHEN 'timestamp without time zone' THEN 6 ");
result.append("WHEN 'geometry' THEN NULL ");
result.append("WHEN 'super' THEN NULL ");
result.append("WHEN 'numeric' THEN regexp_substr (columntype,'[0-9]+',charindex (',',columntype))::INTEGER ");
result.append("WHEN 'varbyte' THEN NULL ");
result.append("WHEN 'geography' THEN NULL ");
result.append("WHEN 'intervaly2m' THEN 0 ");
result.append("WHEN 'intervald2s' THEN 6 ");
result.append("ELSE 0 END AS SMALLINT) AS DECIMAL_DIGITS, ");
result.append("CAST(CASE columntype ");
result.append("WHEN 'varbyte' THEN 2 ");
result.append("WHEN 'geography' THEN 2 ");
result.append("when 'varchar' THEN 0 ");
result.append("when 'character varying' THEN 0 ");
result.append("when 'char' THEN 0 ");
result.append("when 'character' THEN 0 ");
result.append("when 'nchar' THEN 0 ");
result.append("when 'bpchar' THEN 0 ");
result.append("when 'nvarchar' THEN 0 ");
result.append("ELSE 10 END AS SMALLINT) AS NUM_PREC_RADIX, ");
result.append("CAST(NULL AS SMALLINT) AS NULLABLE, NULL AS REMARKS, NULL AS COLUMN_DEF, ");
result.append("CAST(CASE columntype_rep ");
result.append("WHEN 'text' THEN 12 ");
result.append("WHEN 'bit' THEN -7 ");
result.append("WHEN 'bool' THEN -7 ");
result.append("WHEN 'boolean' THEN -7 ");
result.append("WHEN 'varchar' THEN 12 ");
result.append("WHEN 'character varying' THEN 12 ");
result.append("WHEN 'char' THEN 1 ");
result.append("WHEN 'character' THEN 1 ");
result.append("WHEN 'nchar' THEN 12 ");
result.append("WHEN 'bpchar' THEN 1 ");
result.append("WHEN 'nvarchar' THEN 12 ");
result.append("WHEN '\"char\"' THEN 1 ");
result.append("WHEN 'date' THEN 9 ");
result.append("WHEN 'time' THEN 9 ");
result.append("WHEN 'time without time zone' THEN 9 ");
result.append("WHEN 'timetz' THEN 9 ");
result.append("WHEN 'time with time zone' THEN 9 ");
result.append("WHEN 'timestamp' THEN 9 ");
result.append("WHEN 'timestamp without time zone' THEN 9 ");
result.append("WHEN 'timestamptz' THEN 9 ");
result.append("WHEN 'timestamp with time zone' THEN 9 ");
result.append("WHEN 'smallint' THEN 5 ");
result.append("WHEN 'int2' THEN 5 ");
result.append("WHEN 'integer' THEN 4 ");
result.append("WHEN 'int' THEN 4 ");
result.append("WHEN 'int4' THEN 4 ");
result.append("WHEN 'bigint' THEN -5 ");
result.append("WHEN 'int8' THEN -5 ");
result.append("WHEN 'decimal' THEN 3 ");
result.append("WHEN 'real' THEN 7 ");
result.append("WHEN 'float4' THEN 7 ");
result.append("WHEN 'double precision' THEN 8 ");
result.append("WHEN 'float8' THEN 8 ");
result.append("WHEN 'float' THEN 6 ");
result.append("WHEN 'numeric' THEN 2 ");
result.append("WHEN 'bytea' THEN -2 ");
result.append("WHEN 'oid' THEN -5 ");
result.append("WHEN 'name' THEN 12 ");
result.append("WHEN 'ARRAY' THEN 2003 ");
result.append("WHEN 'geometry' THEN -4 ");
result.append("WHEN 'super' THEN -1 ");
result.append("WHEN 'varbyte' THEN -4 ");
result.append("WHEN 'geography' THEN -4 ");
result.append("WHEN 'intervaly2m' THEN 107 ");
result.append("WHEN 'intervald2s' THEN 110 ");
result.append("ELSE 0 END AS SMALLINT) AS SQL_DATA_TYPE, ");
result.append("CAST(case columntype_rep ");
result.append("when 'date' THEN 1 ");
result.append("when 'time' THEN 2 ");
result.append("when 'time without time zone' THEN 2 ");
result.append("when 'timetz' THEN 2 ");
result.append("when 'time with time zone' THEN 2 ");
result.append("when 'timestamp with time zone' THEN 3 ");
result.append("when 'timestamptz' THEN 3 ");
result.append("when 'timestamp' THEN 3 ");
result.append("when 'timestamp without time zone' THEN 3 ");
result.append("else NULL END AS SMALLINT) as SQL_DATETIME_SUB, CASE ");
result.append("WHEN LEFT (columntype,7) = 'varchar' THEN isnull(nullif(regexp_substr (columntype,'[0-9]+',7),''),'0')::INTEGER ");
result.append("WHEN LEFT (columntype,4) = 'char' THEN isnull(nullif(regexp_substr (columntype,'[0-9]+',4),''),'0')::INTEGER ");
result.append("WHEN columntype = 'string' THEN 16383 ELSE NULL ");
result.append("END AS CHAR_OCTET_LENGTH, columnnum AS ORDINAL_POSITION, ");
result.append("NULL AS IS_NULLABLE ");
/* result.append("NULL AS IS_NULLABLE, NULL AS SCOPE_CATALOG, NULL AS SCOPE_SCHEMA, ");
result.append("NULL AS SCOPE_TABLE, NULL AS SOURCE_DATA_TYPE, 'NO' AS IS_AUTOINCREMENT, ");
result.append("'NO' as IS_GENERATEDCOLUMN ");
*/
result.append("FROM (select lbv_cols.schemaname, ");
result.append("lbv_cols.tablename, lbv_cols.columnname,");
result.append("REGEXP_REPLACE(REGEXP_REPLACE(lbv_cols.columntype,'\\\\(.*\\\\)'),'^_.+','ARRAY') as columntype_rep,");
result.append("columntype, ");
result.append("lbv_cols.columnnum ");
result.append("from pg_get_late_binding_view_cols() lbv_cols( ");
result.append("schemaname name, tablename name, columnname name, ");
result.append("columntype text, columnnum int)) lbv_columns ");
result.append(" WHERE true ");
// Apply the filters to the column list for late binding view.
result.append(catalogFilter);
filterClause[0] = '\0';
addLikeOrEqualFilterCondition(pStmt, filterClause, "schemaname", (char *)pSchemaName, cbSchemaName);
addLikeOrEqualFilterCondition(pStmt, filterClause, "tablename", (char *)pTableName, cbTableName);
addLikeOrEqualFilterCondition(pStmt, filterClause, "columnname", (char *)pColumnName, cbColumnName);
result.append(filterClause);
rs_strncpy(pszCatalogQuery, result.c_str(), MAX_CATALOG_QUERY_LEN);
}