[libgda] postgresql: added support for version > 11.0



commit 357daa9c8df5646cbaa3647b26dd4d0a7c8b6b46
Author: Daniel Espinosa Ortiz <esodan gmail com>
Date:   Wed Jan 9 18:08:08 2019 -0600

    postgresql: added support for version > 11.0

 .gitlab-ci.yml                                   |   2 +-
 providers/reuseable/postgres/gda-postgres-meta.c | 230 +++++++++++++++++++----
 2 files changed, 194 insertions(+), 38 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index d0193bf11..c1e28ec3e 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -5,7 +5,7 @@
 image: ubuntu:devel
 
 services:
-  - postgres:10
+  - postgres
 
 stages:
   - build
diff --git a/providers/reuseable/postgres/gda-postgres-meta.c 
b/providers/reuseable/postgres/gda-postgres-meta.c
index 0acfe7d9c..25b10bae4 100644
--- a/providers/reuseable/postgres/gda-postgres-meta.c
+++ b/providers/reuseable/postgres/gda-postgres-meta.c
@@ -268,6 +268,176 @@ static gchar *internal_sql[] = {
        "SELECT current_database() AS index_catalog, nc2.nspname AS index_schema, c2.relname AS index_name, 
current_database() AS table_catalog, nc.nspname AS table_schema, c.relname AS table_name, a.attname, NULL, 
(ss.a).n FROM pg_catalog.pg_index i, (SELECT information_schema._pg_expandarray(indkey) AS a FROM 
pg_catalog.pg_index WHERE indexrelid = ##oid::guint) ss, pg_catalog.pg_class c INNER JOIN pg_namespace nc ON 
(c.relnamespace = nc.oid) INNER JOIN pg_catalog.pg_attribute a ON (a.attrelid = c.oid), pg_catalog.pg_class 
c2 INNER JOIN pg_namespace nc2 ON (c2.relnamespace = nc2.oid) WHERE i.indexrelid = ##oid::guint AND (ss.a).x 
!= 0 AND a.attnum = (ss.a).x AND c.oid = i.indrelid AND i.indexrelid = c2.oid AND 
pg_catalog.pg_table_is_visible(c.oid) UNION SELECT current_database() AS index_catalog, nc2.nspname AS 
index_schema, c2.relname AS index_name, current_database() AS table_catalog, nc.nspname AS table_schema, 
c.relname AS table_name, NULL, pg_get_indexdef (i.indexrelid, (ss.a
 ).n, fal
 se), (ss.a).n FROM pg_catalog.pg_index i, (SELECT information_schema._pg_expandarray(indkey) AS a FROM 
pg_catalog.pg_index WHERE indexrelid = ##oid::guint) ss, pg_catalog.pg_class c INNER JOIN pg_namespace nc ON 
(c.relnamespace = nc.oid), pg_catalog.pg_class c2 INNER JOIN pg_namespace nc2 ON (c2.relnamespace = nc2.oid) 
WHERE i.indexrelid = ##oid::guint AND (ss.a).x = 0 AND c.oid = i.indrelid AND i.indexrelid = c2.oid AND 
pg_catalog.pg_table_is_visible(c.oid) order by 9"
 };
 
+// PostgreSQL > 11.0
+static gchar *internal_sql_11[] = {
+       /* I_STMT_CATALOG */
+       "SELECT pg_catalog.current_database()",
+
+       /* I_STMT_BTYPES */
+       "SELECT t.typname, 'pg_catalog.' || t.typname, 'gchararray', pg_catalog.obj_description(t.oid), NULL, 
CASE WHEN t.typname ~ '^_' THEN TRUE WHEN typtype = 'p' THEN TRUE WHEN t.typname in ('any', 'anyarray', 
'anyelement', 'cid', 'cstring', 'int2vector', 'internal', 'language_handler', 'oidvector', 'opaque', 
'record', 'refcursor', 'regclass', 'regoper', 'regoperator', 'regproc', 'regprocedure', 'regtype', 'SET', 
'smgr', 'tid', 'trigger', 'unknown', 'void', 'xid', 'oid', 'aclitem') THEN TRUE ELSE FALSE END, CAST (t.oid 
AS varchar) FROM pg_catalog.pg_type t, pg_catalog.pg_user u, pg_catalog.pg_namespace n WHERE 
t.typowner=u.usesysid AND n.oid = t.typnamespace AND pg_catalog.pg_type_is_visible(t.oid) AND (typtype='b' OR 
typtype='p') AND typelem = 0",
+
+       /* I_STMT_SCHEMAS */
+       "SELECT current_database() AS catalog_name, n.nspname AS schema_name, u.rolname AS schema_owner, CASE 
WHEN n.nspname ~ '^pg_' THEN TRUE WHEN n.nspname = 'information_schema' THEN TRUE ELSE FALSE END, CASE WHEN 
n.nspname = 'public' THEN TRUE ELSE FALSE END AS schema_default FROM pg_namespace n, pg_roles u WHERE 
n.nspowner = u.oid AND current_database() = ##cat::string",
+
+       /* I_STMT_SCHEMAS_ALL */
+       "SELECT current_database() AS catalog_name, n.nspname AS schema_name, u.rolname AS schema_owner, CASE 
WHEN n.nspname ~ '^pg_' THEN TRUE WHEN n.nspname = 'information_schema' THEN TRUE ELSE FALSE END, CASE WHEN 
n.nspname = 'public' THEN TRUE ELSE FALSE END AS schema_default FROM pg_namespace n, pg_roles u WHERE 
n.nspowner = u.oid",
+
+       /* I_STMT_SCHEMA_NAMED */
+       "SELECT current_database() AS catalog_name, n.nspname AS schema_name, u.rolname AS schema_owner, CASE 
WHEN n.nspname ~ '^pg_' THEN TRUE WHEN n.nspname = 'information_schema' THEN TRUE ELSE FALSE END, CASE WHEN 
n.nspname = 'public' THEN TRUE ELSE FALSE END AS schema_default FROM pg_namespace n, pg_roles u WHERE 
n.nspowner = u.oid AND current_database() = ##cat::string AND n.nspname = ##name::string",
+
+       /* I_STMT_TABLES */
+       "SELECT current_database() AS table_catalog, nc.nspname AS table_schema, c.relname AS table_name, 
CASE WHEN nc.oid = pg_my_temp_schema() THEN 'LOCAL TEMPORARY' WHEN c.relkind = 'r' THEN 'BASE TABLE' WHEN 
c.relkind = 'v' THEN 'VIEW' ELSE NULL END AS table_type, CASE WHEN c.relkind = 'r' THEN TRUE ELSE FALSE END, 
pg_catalog.obj_description(c.oid), CASE WHEN pg_catalog.pg_table_is_visible(c.oid) IS TRUE AND 
nc.nspname!='pg_catalog' THEN c.relname ELSE coalesce (nc.nspname || '.', '') || c.relname END, coalesce 
(nc.nspname || '.', '') || c.relname, o.rolname FROM pg_namespace nc, pg_class c, pg_roles o WHERE 
current_database() = ##cat::string AND nc.nspname = ##schema::string AND c.relnamespace = nc.oid AND 
(c.relkind = ANY (ARRAY['r', 'v'])) AND NOT pg_is_other_temp_schema(nc.oid) AND (pg_has_role(c.relowner, 
'USAGE') OR has_table_privilege(c.oid, 'SELECT') OR has_table_privilege(c.oid, 'INSERT') OR 
has_table_privilege(c.oid, 'UPDATE') OR has_table_privilege(c.oid, 'DELETE') O
 R has_ta
 ble_privilege(c.oid, 'REFERENCES') OR has_table_privilege(c.oid, 'TRIGGER')) AND o.oid=c.relowner",
+
+       /* I_STMT_TABLES_ALL */
+       "SELECT current_database() AS table_catalog, nc.nspname AS table_schema, c.relname AS table_name, 
CASE WHEN nc.oid = pg_my_temp_schema() THEN 'LOCAL TEMPORARY' WHEN c.relkind = 'r' THEN 'BASE TABLE' WHEN 
c.relkind = 'v' THEN 'VIEW' ELSE NULL END AS table_type, CASE WHEN c.relkind = 'r' THEN TRUE ELSE FALSE END, 
pg_catalog.obj_description(c.oid), CASE WHEN pg_catalog.pg_table_is_visible(c.oid) IS TRUE AND 
nc.nspname!='pg_catalog' THEN c.relname ELSE coalesce (nc.nspname || '.', '') || c.relname END, coalesce 
(nc.nspname || '.', '') || c.relname, o.rolname FROM pg_namespace nc, pg_class c, pg_roles o WHERE 
c.relnamespace = nc.oid AND (c.relkind = ANY (ARRAY['r', 'v'])) AND NOT pg_is_other_temp_schema(nc.oid) AND 
(pg_has_role(c.relowner, 'USAGE') OR has_table_privilege(c.oid, 'SELECT') OR has_table_privilege(c.oid, 
'INSERT') OR has_table_privilege(c.oid, 'UPDATE') OR has_table_privilege(c.oid, 'DELETE') OR 
has_table_privilege(c.oid, 'REFERENCES') OR has_table_privilege(c.oid, 
 'TRIGGER
 ')) AND o.oid=c.relowner",
+
+       /* I_STMT_TABLE_NAMED */
+       "SELECT current_database() AS table_catalog, nc.nspname AS table_schema, c.relname AS table_name, 
CASE WHEN nc.oid = pg_my_temp_schema() THEN 'LOCAL TEMPORARY' WHEN c.relkind = 'r' THEN 'BASE TABLE' WHEN 
c.relkind = 'v' THEN 'VIEW' ELSE NULL END AS table_type, CASE WHEN c.relkind = 'r' THEN TRUE ELSE FALSE END, 
pg_catalog.obj_description(c.oid), CASE WHEN pg_catalog.pg_table_is_visible(c.oid) IS TRUE AND 
nc.nspname!='pg_catalog' THEN c.relname ELSE coalesce (nc.nspname || '.', '') || c.relname END, coalesce 
(nc.nspname || '.', '') || c.relname, o.rolname FROM pg_namespace nc, pg_class c, pg_roles o WHERE 
current_database() = ##cat::string AND nc.nspname = ##schema::string AND c.relnamespace = nc.oid AND 
(c.relkind = ANY (ARRAY['r', 'v'])) AND NOT pg_is_other_temp_schema(nc.oid) AND (pg_has_role(c.relowner, 
'USAGE') OR has_table_privilege(c.oid, 'SELECT') OR has_table_privilege(c.oid, 'INSERT') OR 
has_table_privilege(c.oid, 'UPDATE') OR has_table_privilege(c.oid, 'DELETE') O
 R has_ta
 ble_privilege(c.oid, 'REFERENCES') OR has_table_privilege(c.oid, 'TRIGGER')) AND o.oid=c.relowner AND 
c.relname = ##name::string",
+
+       /* I_STMT_VIEWS */
+       "SELECT current_database() AS table_catalog, nc.nspname AS table_schema, c.relname AS table_name, 
pg_catalog.pg_get_viewdef(c.oid, TRUE), NULL, CASE WHEN c.relkind = 'r' THEN TRUE ELSE FALSE END FROM 
pg_namespace nc, pg_class c WHERE current_database() = ##cat::string AND nc.nspname = ##schema::string AND 
c.relnamespace = nc.oid AND c.relkind = 'v' AND NOT pg_is_other_temp_schema(nc.oid) AND 
(pg_has_role(c.relowner, 'USAGE') OR has_table_privilege(c.oid, 'SELECT') OR has_table_privilege(c.oid, 
'INSERT') OR has_table_privilege(c.oid, 'UPDATE') OR has_table_privilege(c.oid, 'DELETE') OR 
has_table_privilege(c.oid, 'REFERENCES') OR has_table_privilege(c.oid, 'TRIGGER'))",
+
+       /* I_STMT_VIEWS_ALL */
+       "SELECT current_database() AS table_catalog, nc.nspname AS table_schema, c.relname AS table_name, 
pg_catalog.pg_get_viewdef(c.oid, TRUE), NULL, CASE WHEN c.relkind = 'r' THEN TRUE ELSE FALSE END FROM 
pg_namespace nc, pg_class c WHERE c.relnamespace = nc.oid AND c.relkind = 'v' AND NOT 
pg_is_other_temp_schema(nc.oid) AND (pg_has_role(c.relowner, 'USAGE') OR has_table_privilege(c.oid, 'SELECT') 
OR has_table_privilege(c.oid, 'INSERT') OR has_table_privilege(c.oid, 'UPDATE') OR has_table_privilege(c.oid, 
'DELETE') OR has_table_privilege(c.oid, 'REFERENCES') OR has_table_privilege(c.oid, 'TRIGGER'))",
+
+       /* I_STMT_VIEW_NAMED */
+       "SELECT current_database() AS table_catalog, nc.nspname AS table_schema, c.relname AS table_name, 
pg_catalog.pg_get_viewdef(c.oid, TRUE), NULL, CASE WHEN c.relkind = 'r' THEN TRUE ELSE FALSE END FROM 
pg_namespace nc, pg_class c WHERE current_database() = ##cat::string AND nc.nspname = ##schema::string AND 
c.relnamespace = nc.oid AND c.relkind = 'v' AND NOT pg_is_other_temp_schema(nc.oid) AND 
(pg_has_role(c.relowner, 'USAGE') OR has_table_privilege(c.oid, 'SELECT') OR has_table_privilege(c.oid, 
'INSERT') OR has_table_privilege(c.oid, 'UPDATE') OR has_table_privilege(c.oid, 'DELETE') OR 
has_table_privilege(c.oid, 'REFERENCES') OR has_table_privilege(c.oid, 'TRIGGER')) AND c.relname = 
##name::string",
+
+       /* I_STMT_COLUMNS_OF_TABLE */
+       "SELECT current_database(), nc.nspname, c.relname, a.attname, a.attnum, pg_get_expr(ad.adbin, 
ad.adrelid), CASE WHEN a.attnotnull OR t.typtype = 'd' AND t.typnotnull THEN FALSE ELSE TRUE END, CASE WHEN 
t.typelem <> 0 AND t.typlen = -1 THEN NULL ELSE coalesce (nt.nspname || '.', '') || t.typname END, CASE WHEN 
t.typelem <> 0 AND t.typlen = -1 THEN 'COL' || current_database() || '.' || nc.nspname || '.' || c.relname || 
'.' || a.attnum ELSE NULL END, 'gchararray', 
information_schema._pg_char_max_length(information_schema._pg_truetypid(a.*, t.*), 
information_schema._pg_truetypmod(a.*, t.*)), 
information_schema._pg_char_octet_length(information_schema._pg_truetypid(a.*, t.*), 
information_schema._pg_truetypmod(a.*, t.*)), 
information_schema._pg_numeric_precision(information_schema._pg_truetypid(a.*, t.*), 
information_schema._pg_truetypmod(a.*, t.*)), 
information_schema._pg_numeric_scale(information_schema._pg_truetypid(a.*, t.*), 
information_schema._pg_truetypmod(a.*, t.*)), info
 rmation_
 schema._pg_datetime_precision(information_schema._pg_truetypid(a.*, t.*), 
information_schema._pg_truetypmod(a.*, t.*)), NULL, NULL, NULL, NULL, NULL, NULL, CASE WHEN 
pg_get_expr(ad.adbin, ad.adrelid) LIKE 'nextval(%' THEN '" GDA_EXTRA_AUTO_INCREMENT "' ELSE NULL END, CASE 
WHEN c.relkind = 'r' THEN TRUE ELSE FALSE END, pg_catalog.col_description(c.oid, a.attnum), CAST (t.oid AS 
varchar) FROM pg_attribute a LEFT JOIN pg_attrdef ad ON a.attrelid = ad.adrelid AND a.attnum = ad.adnum, 
pg_class c, pg_namespace nc, pg_type t JOIN pg_namespace nt ON t.typnamespace = nt.oid LEFT JOIN (pg_type bt 
JOIN pg_namespace nbt ON bt.typnamespace = nbt.oid) ON t.typtype = 'd' AND t.typbasetype = bt.oid WHERE 
current_database() = ##cat::string AND nc.nspname = ##schema::string AND c.relname = ##name::string AND 
a.attrelid = c.oid AND a.atttypid = t.oid AND nc.oid = c.relnamespace AND NOT pg_is_other_temp_schema(nc.oid) 
AND a.attnum > 0 AND NOT a.attisdropped AND (c.relkind = ANY (ARRAY['r', 'v']
 )) AND (
 pg_has_role(c.relowner, 'USAGE') OR has_table_privilege(c.oid, 'SELECT') OR has_table_privilege(c.oid, 
'INSERT') OR has_table_privilege(c.oid, 'UPDATE') OR has_table_privilege(c.oid, 'REFERENCES'))",
+
+       /* I_STMT_COLUMNS_ALL */
+       "SELECT current_database(), nc.nspname, c.relname, a.attname, a.attnum, pg_get_expr(ad.adbin, 
ad.adrelid), CASE WHEN a.attnotnull OR t.typtype = 'd' AND t.typnotnull THEN FALSE ELSE TRUE END, CASE WHEN 
t.typelem <> 0 AND t.typlen = -1 THEN NULL ELSE coalesce (nt.nspname || '.', '') || t.typname END, CASE WHEN 
t.typelem <> 0 AND t.typlen = -1 THEN 'COL' || current_database() || '.' || nc.nspname || '.' || c.relname || 
'.' || a.attnum ELSE NULL END, 'gchararray', 
information_schema._pg_char_max_length(information_schema._pg_truetypid(a.*, t.*), 
information_schema._pg_truetypmod(a.*, t.*)), 
information_schema._pg_char_octet_length(information_schema._pg_truetypid(a.*, t.*), 
information_schema._pg_truetypmod(a.*, t.*)), 
information_schema._pg_numeric_precision(information_schema._pg_truetypid(a.*, t.*), 
information_schema._pg_truetypmod(a.*, t.*)), 
information_schema._pg_numeric_scale(information_schema._pg_truetypid(a.*, t.*), 
information_schema._pg_truetypmod(a.*, t.*)), info
 rmation_
 schema._pg_datetime_precision(information_schema._pg_truetypid(a.*, t.*), 
information_schema._pg_truetypmod(a.*, t.*)), NULL, NULL, NULL, NULL, NULL, NULL, CASE WHEN 
pg_get_expr(ad.adbin, ad.adrelid) LIKE 'nextval(%' THEN '" GDA_EXTRA_AUTO_INCREMENT "' ELSE NULL END, CASE 
WHEN c.relkind = 'r' THEN TRUE ELSE FALSE END, pg_catalog.col_description(c.oid, a.attnum), CAST (t.oid AS 
varchar) FROM pg_attribute a LEFT JOIN pg_attrdef ad ON a.attrelid = ad.adrelid AND a.attnum = ad.adnum, 
pg_class c, pg_namespace nc, pg_type t JOIN pg_namespace nt ON t.typnamespace = nt.oid LEFT JOIN (pg_type bt 
JOIN pg_namespace nbt ON bt.typnamespace = nbt.oid) ON t.typtype = 'd' AND t.typbasetype = bt.oid WHERE 
a.attrelid = c.oid AND a.atttypid = t.oid AND nc.oid = c.relnamespace AND NOT pg_is_other_temp_schema(nc.oid) 
AND a.attnum > 0 AND NOT a.attisdropped AND (c.relkind = ANY (ARRAY['r', 'v'])) AND (pg_has_role(c.relowner, 
'USAGE') OR has_table_privilege(c.oid, 'SELECT') OR has_table_privilege(
 c.oid, '
 INSERT') OR has_table_privilege(c.oid, 'UPDATE') OR has_table_privilege(c.oid, 'REFERENCES'))",
+
+       /* I_STMT_TABLES_CONSTRAINTS */
+       "SELECT current_database() AS constraint_catalog, nc.nspname AS constraint_schema, c.conname AS 
constraint_name, current_database() AS table_catalog, nr.nspname AS table_schema, r.relname AS table_name, 
CASE c.contype WHEN 'c' THEN 'CHECK' WHEN 'f' THEN 'FOREIGN KEY' WHEN 'p' THEN 'PRIMARY KEY' WHEN 'u' THEN 
'UNIQUE' ELSE NULL END AS constraint_type, CASE c.contype WHEN 'c' THEN c.consrc ELSE NULL END, CASE WHEN 
c.condeferrable THEN TRUE ELSE FALSE END AS is_deferrable, CASE WHEN c.condeferred THEN TRUE ELSE FALSE END 
AS initially_deferred FROM pg_namespace nc, pg_namespace nr, pg_constraint c, pg_class r WHERE nc.oid = 
c.connamespace AND nr.oid = r.relnamespace AND c.conrelid = r.oid AND r.relkind = 'r' AND NOT 
pg_is_other_temp_schema(nr.oid) AND (pg_has_role(r.relowner, 'USAGE') OR has_table_privilege(r.oid, 'INSERT') 
OR has_table_privilege(r.oid, 'UPDATE') OR has_table_privilege(r.oid, 'DELETE') OR has_table_privilege(r.oid, 
'REFERENCES') OR has_table_privilege(r.oid, 'T
 RIGGER')
 ) AND current_database() = ##cat::string AND nr.nspname = ##schema::string AND r.relname = ##name::string "
+       "UNION SELECT current_database() AS constraint_catalog, nr.nspname AS constraint_schema, (((((nr.oid 
|| '_') || r.oid) || '_') || a.attnum) || '_not_null') AS constraint_name, current_database() AS 
table_catalog, nr.nspname AS table_schema, r.relname AS table_name, 'CHECK' AS constraint_type, a.attname || 
' IS NOT NULL', FALSE AS is_deferrable, FALSE AS initially_deferred FROM pg_namespace nr, pg_class r, 
pg_attribute a WHERE nr.oid = r.relnamespace AND r.oid = a.attrelid AND a.attnotnull AND a.attnum > 0 AND NOT 
a.attisdropped AND r.relkind = 'r' AND NOT pg_is_other_temp_schema(nr.oid) AND (pg_has_role(r.relowner, 
'USAGE') OR has_table_privilege(r.oid, 'SELECT') OR has_table_privilege(r.oid, 'INSERT') OR 
has_table_privilege(r.oid, 'UPDATE') OR has_table_privilege(r.oid, 'DELETE') OR has_table_privilege(r.oid, 
'REFERENCES') OR has_table_privilege(r.oid, 'TRIGGER')) AND current_database() = ##cat::string AND nr.nspname 
= ##schema::string AND r.relname = ##name::string",
+
+       /* I_STMT_TABLES_CONSTRAINTS_ALL */
+       "SELECT current_database() AS constraint_catalog, nc.nspname AS constraint_schema, c.conname AS 
constraint_name, current_database() AS table_catalog, nr.nspname AS table_schema, r.relname AS table_name, 
CASE c.contype WHEN 'c' THEN 'CHECK' WHEN 'f' THEN 'FOREIGN KEY' WHEN 'p' THEN 'PRIMARY KEY' WHEN 'u' THEN 
'UNIQUE' ELSE NULL END AS constraint_type, CASE c.contype WHEN 'c' THEN c.consrc ELSE NULL END, CASE WHEN 
c.condeferrable THEN TRUE ELSE FALSE END AS is_deferrable, CASE WHEN c.condeferred THEN TRUE ELSE FALSE END 
AS initially_deferred FROM pg_namespace nc, pg_namespace nr, pg_constraint c, pg_class r WHERE nc.oid = 
c.connamespace AND nr.oid = r.relnamespace AND c.conrelid = r.oid AND r.relkind = 'r' AND NOT 
pg_is_other_temp_schema(nr.oid) AND (pg_has_role(r.relowner, 'USAGE') OR has_table_privilege(r.oid, 'INSERT') 
OR has_table_privilege(r.oid, 'UPDATE') OR has_table_privilege(r.oid, 'DELETE') OR has_table_privilege(r.oid, 
'REFERENCES') OR has_table_privilege(r.oid, 'T
 RIGGER')
 ) "
+       "UNION SELECT current_database() AS constraint_catalog, nr.nspname AS constraint_schema, (((((nr.oid 
|| '_') || r.oid) || '_') || a.attnum) || '_not_null') AS constraint_name, current_database() AS 
table_catalog, nr.nspname AS table_schema, r.relname AS table_name, 'CHECK' AS constraint_type, a.attname || 
' IS NOT NULL', FALSE AS is_deferrable, FALSE AS initially_deferred FROM pg_namespace nr, pg_class r, 
pg_attribute a WHERE nr.oid = r.relnamespace AND r.oid = a.attrelid AND a.attnotnull AND a.attnum > 0 AND NOT 
a.attisdropped AND r.relkind = 'r' AND NOT pg_is_other_temp_schema(nr.oid) AND (pg_has_role(r.relowner, 
'USAGE') OR has_table_privilege(r.oid, 'SELECT') OR has_table_privilege(r.oid, 'INSERT') OR 
has_table_privilege(r.oid, 'UPDATE') OR has_table_privilege(r.oid, 'DELETE') OR has_table_privilege(r.oid, 
'REFERENCES') OR has_table_privilege(r.oid, 'TRIGGER'))",
+
+       /* I_STMT_TABLES_CONSTRAINT_NAMED */
+       "SELECT constraint_catalog, constraint_schema, constraint_name, table_catalog, table_schema, 
table_name, constraint_type, NULL, CASE WHEN is_deferrable = 'YES' THEN TRUE ELSE FALSE END, CASE WHEN 
initially_deferred = 'YES' THEN TRUE ELSE FALSE END FROM information_schema.table_constraints WHERE 
table_catalog = ##cat::string AND table_schema = ##schema::string AND table_name = ##name::string AND 
constraint_name = ##name2::string",
+
+       /* I_STMT_REF_CONSTRAINTS */
+       "SELECT current_database(), nt.nspname, t.relname, c.conname, current_database(), nref.nspname, 
ref.relname, pkc.conname, CASE c.confmatchtype WHEN 'f' THEN 'FULL' WHEN 'p' THEN 'PARTIAL' WHEN 'u' THEN 
'NONE' ELSE NULL END AS match_option, CASE c.confupdtype WHEN 'c' THEN 'CASCADE' WHEN 'n' THEN 'SET NULL' 
WHEN 'd' THEN 'SET DEFAULT' WHEN 'r' THEN 'RESTRICT' WHEN 'a' THEN 'NO ACTION' ELSE NULL END AS update_rule, 
CASE c.confdeltype WHEN 'c' THEN 'CASCADE' WHEN 'n' THEN 'SET NULL' WHEN 'd' THEN 'SET DEFAULT' WHEN 'r' THEN 
'RESTRICT' WHEN 'a' THEN 'NO ACTION' ELSE NULL END AS delete_rule FROM pg_constraint c INNER JOIN pg_class t 
ON (c.conrelid=t.oid) INNER JOIN pg_namespace nt ON (nt.oid=t.relnamespace) INNER JOIN pg_class ref ON 
(c.confrelid=ref.oid) INNER JOIN pg_namespace nref ON (nref.oid=ref.relnamespace) INNER JOIN pg_constraint 
pkc ON (c.confrelid = pkc.conrelid AND information_schema._pg_keysequal(c.confkey, pkc.conkey) AND 
pkc.contype='p') WHERE c.contype = 'f' AND 
 current_
 database() = ##cat::string AND nt.nspname = ##schema::string AND t.relname = ##name::string AND c.conname = 
##name2::string",
+
+       /* I_STMT_REF_CONSTRAINTS_ALL */
+       "SELECT current_database(), nt.nspname, t.relname, c.conname, current_database(), nref.nspname, 
ref.relname, pkc.conname, CASE c.confmatchtype WHEN 'f' THEN 'FULL' WHEN 'p' THEN 'PARTIAL' WHEN 'u' THEN 
'NONE' ELSE NULL END AS match_option, CASE c.confupdtype WHEN 'c' THEN 'CASCADE' WHEN 'n' THEN 'SET NULL' 
WHEN 'd' THEN 'SET DEFAULT' WHEN 'r' THEN 'RESTRICT' WHEN 'a' THEN 'NO ACTION' ELSE NULL END AS update_rule, 
CASE c.confdeltype WHEN 'c' THEN 'CASCADE' WHEN 'n' THEN 'SET NULL' WHEN 'd' THEN 'SET DEFAULT' WHEN 'r' THEN 
'RESTRICT' WHEN 'a' THEN 'NO ACTION' ELSE NULL END AS delete_rule FROM pg_constraint c INNER JOIN pg_class t 
ON (c.conrelid=t.oid) INNER JOIN pg_namespace nt ON (nt.oid=t.relnamespace) INNER JOIN pg_class ref ON 
(c.confrelid=ref.oid) INNER JOIN pg_namespace nref ON (nref.oid=ref.relnamespace) INNER JOIN pg_constraint 
pkc ON (c.confrelid = pkc.conrelid AND information_schema._pg_keysequal(c.confkey, pkc.conkey) AND 
pkc.contype='p') WHERE c.contype = 'f'",
+
+       /* I_STMT_KEY_COLUMN_USAGE */
+       "SELECT table_catalog, table_schema, table_name, constraint_name, column_name, ordinal_position FROM 
information_schema.key_column_usage WHERE table_catalog = ##cat::string AND table_schema = ##schema::string 
AND table_name = ##name::string AND constraint_name = ##name2::string",
+
+       /* I_STMT_KEY_COLUMN_USAGE_ALL */
+       "SELECT table_catalog, table_schema, table_name, constraint_name, column_name, ordinal_position FROM 
information_schema.key_column_usage",
+
+       /* I_STMT_CHECK_COLUMN_USAGE */
+       "SELECT current_database() AS table_catalog, nr.nspname AS table_schema, r.relname AS table_name, 
c.conname AS constraint_name,a.attname FROM pg_namespace nc, pg_namespace nr, pg_constraint c, pg_class r, 
pg_attribute a, (SELECT sc.oid, information_schema._pg_expandarray (sc.conkey) as x FROM pg_constraint sc 
WHERE sc.contype = 'c') ss WHERE nc.oid = c.connamespace AND nr.oid = r.relnamespace AND c.conrelid = r.oid 
AND r.relkind = 'r' AND NOT pg_is_other_temp_schema(nr.oid) AND (pg_has_role(r.relowner, 'USAGE') OR 
has_table_privilege(r.oid, 'INSERT') OR has_table_privilege(r.oid, 'UPDATE') OR has_table_privilege(r.oid, 
'DELETE') OR has_table_privilege(r.oid, 'REFERENCES') OR has_table_privilege(r.oid, 'TRIGGER')) AND c.contype 
= 'c' AND ss.oid = c.oid AND a.attrelid = r.oid AND a.attnum = (ss.x).x AND current_database() = 
##cat::string AND nr.nspname = ##schema::string AND r.relname = ##name::string AND c.conname = 
##name2::string "
+       "UNION SELECT current_database() AS table_catalog, nr.nspname AS table_schema, r.relname AS 
table_name, (((((nr.oid || '_') || r.oid) || '_') || a.attnum) || '_not_null') AS constraint_name, a.attname 
FROM pg_namespace nr, pg_class r, pg_attribute a WHERE nr.oid = r.relnamespace AND r.oid = a.attrelid AND 
a.attnotnull AND a.attnum > 0 AND NOT a.attisdropped AND r.relkind = 'r' AND NOT 
pg_is_other_temp_schema(nr.oid) AND (pg_has_role(r.relowner, 'USAGE') OR has_table_privilege(r.oid, 'SELECT') 
OR has_table_privilege(r.oid, 'INSERT') OR has_table_privilege(r.oid, 'UPDATE') OR has_table_privilege(r.oid, 
'DELETE') OR has_table_privilege(r.oid, 'REFERENCES') OR has_table_privilege(r.oid, 'TRIGGER')) AND 
current_database() = ##cat::string AND nr.nspname = ##schema::string AND r.relname = ##name::string AND 
(((((nr.oid || '_') || r.oid) || '_') || a.attnum) || '_not_null') = ##name2::string",
+
+       /* I_STMT_CHECK_COLUMN_USAGE_ALL */
+       "SELECT current_database() AS table_catalog, nr.nspname AS table_schema, r.relname AS table_name, 
c.conname AS constraint_name,a.attname FROM pg_namespace nc, pg_namespace nr, pg_constraint c, pg_class r, 
pg_attribute a, (SELECT sc.oid, information_schema._pg_expandarray (sc.conkey) as x FROM pg_constraint sc 
WHERE sc.contype = 'c') ss WHERE nc.oid = c.connamespace AND nr.oid = r.relnamespace AND c.conrelid = r.oid 
AND r.relkind = 'r' AND NOT pg_is_other_temp_schema(nr.oid) AND (pg_has_role(r.relowner, 'USAGE') OR 
has_table_privilege(r.oid, 'INSERT') OR has_table_privilege(r.oid, 'UPDATE') OR has_table_privilege(r.oid, 
'DELETE') OR has_table_privilege(r.oid, 'REFERENCES') OR has_table_privilege(r.oid, 'TRIGGER')) AND c.contype 
= 'c' AND ss.oid = c.oid AND a.attrelid = r.oid AND a.attnum = (ss.x).x "
+       "UNION SELECT current_database() AS table_catalog, nr.nspname AS table_schema, r.relname AS 
table_name, (((((nr.oid || '_') || r.oid) || '_') || a.attnum) || '_not_null') AS constraint_name, a.attname 
FROM pg_namespace nr, pg_class r, pg_attribute a WHERE nr.oid = r.relnamespace AND r.oid = a.attrelid AND 
a.attnotnull AND a.attnum > 0 AND NOT a.attisdropped AND r.relkind = 'r' AND NOT 
pg_is_other_temp_schema(nr.oid) AND (pg_has_role(r.relowner, 'USAGE') OR has_table_privilege(r.oid, 'SELECT') 
OR has_table_privilege(r.oid, 'INSERT') OR has_table_privilege(r.oid, 'UPDATE') OR has_table_privilege(r.oid, 
'DELETE') OR has_table_privilege(r.oid, 'REFERENCES') OR has_table_privilege(r.oid, 'TRIGGER'))",
+
+       /* I_STMT_UDT */
+       "SELECT pg_catalog.current_database() as cat, n.nspname, t.typname, 'gchararray', 
pg_catalog.obj_description(t.oid), CASE WHEN pg_catalog.pg_type_is_visible(t.oid) IS TRUE THEN t.typname ELSE 
coalesce (n.nspname || '.', '') || t.typname END, coalesce (n.nspname || '.', '') || t.typname, CASE WHEN 
t.typname ~ '^_' THEN TRUE WHEN t.typname in ('any', 'anyarray', 'anyelement', 'cid', 'cstring', 
'int2vector', 'internal', 'language_handler', 'oidvector', 'opaque', 'record', 'refcursor', 'regclass', 
'regoper', 'regoperator', 'regproc', 'regprocedure', 'regtype', 'SET', 'smgr', 'tid', 'trigger', 'unknown', 
'void', 'xid', 'oid', 'aclitem') THEN TRUE ELSE FALSE END, o.rolname FROM pg_catalog.pg_type t, 
pg_catalog.pg_user u, pg_catalog.pg_namespace n , pg_roles o WHERE t.typowner=u.usesysid AND n.oid = 
t.typnamespace AND pg_catalog.pg_type_is_visible(t.oid) AND (t.typrelid != 0 AND (SELECT c.relkind = 'c' FROM 
pg_catalog.pg_class c WHERE c.oid = t.typrelid)) AND o.oid=t.typowner AND 
 pg_catal
 og.current_database() = ##cat::string AND n.nspname = ##schema::string",
+
+       /* I_STMT_UDT_ALL */
+       "SELECT pg_catalog.current_database(), n.nspname, t.typname, 'gchararray', 
pg_catalog.obj_description(t.oid), CASE WHEN pg_catalog.pg_type_is_visible(t.oid) IS TRUE THEN t.typname ELSE 
coalesce (n.nspname || '.', '') || t.typname END, coalesce (n.nspname || '.', '') || t.typname, CASE WHEN 
t.typname ~ '^_' THEN TRUE WHEN t.typname in ('any', 'anyarray', 'anyelement', 'cid', 'cstring', 
'int2vector', 'internal', 'language_handler', 'oidvector', 'opaque', 'record', 'refcursor', 'regclass', 
'regoper', 'regoperator', 'regproc', 'regprocedure', 'regtype', 'SET', 'smgr', 'tid', 'trigger', 'unknown', 
'void', 'xid', 'oid', 'aclitem') THEN TRUE ELSE FALSE END, o.rolname FROM pg_catalog.pg_type t, 
pg_catalog.pg_user u, pg_catalog.pg_namespace n , pg_roles o WHERE t.typowner=u.usesysid AND n.oid = 
t.typnamespace AND pg_catalog.pg_type_is_visible(t.oid) AND (t.typrelid != 0 AND (SELECT c.relkind = 'c' FROM 
pg_catalog.pg_class c WHERE c.oid = t.typrelid)) AND o.oid=t.typowner",
+
+       /* I_STMT_UDT_COLUMNS */
+       "select pg_catalog.current_database(), n.nspname, udt.typname, a.attname, a.attnum, CASE WHEN 
t.typelem <> 0 AND t.typlen = -1 THEN NULL ELSE coalesce (nt.nspname || '.', '') || t.typname END, CASE WHEN 
t.typelem <> 0 AND t.typlen = -1 THEN 'UDT' || current_database() || '.' || n.nspname || '.' || udt.typname 
|| '.' || a.attnum ELSE NULL END, 
information_schema._pg_char_max_length(information_schema._pg_truetypid(a.*, t.*), 
information_schema._pg_truetypmod(a.*, t.*)), 
information_schema._pg_char_octet_length(information_schema._pg_truetypid(a.*, t.*), 
information_schema._pg_truetypmod(a.*, t.*)), 
information_schema._pg_numeric_precision(information_schema._pg_truetypid(a.*, t.*), 
information_schema._pg_truetypmod(a.*, t.*)), 
information_schema._pg_numeric_scale(information_schema._pg_truetypid(a.*, t.*), 
information_schema._pg_truetypmod(a.*, t.*)), 
information_schema._pg_datetime_precision(information_schema._pg_truetypid(a.*, t.*), 
information_schema._pg_truetypmod(a.*, 
 t.*)), N
 ULL, NULL , NULL, NULL, NULL, NULL FROM pg_type udt INNER JOIN pg_namespace n ON (udt.typnamespace=n.oid) 
INNER JOIN pg_attribute a ON (a.attrelid=udt.typrelid) INNER JOIN pg_type t ON (a.atttypid=t.oid) INNER JOIN 
pg_namespace nt ON (t.typnamespace = nt.oid) WHERE udt.typrelid != 0 AND (SELECT c.relkind = 'c' FROM 
pg_catalog.pg_class c WHERE c.oid = udt.typrelid) AND pg_catalog.current_database() = ##cat::string AND 
n.nspname = ##schema::string AND udt.typname = ##name::string",
+
+       /* I_STMT_UDT_COLUMNS_ALL */
+       "select pg_catalog.current_database(), n.nspname, udt.typname, a.attname, a.attnum, CASE WHEN 
t.typelem <> 0 AND t.typlen = -1 THEN NULL ELSE coalesce (nt.nspname || '.', '') || t.typname END, CASE WHEN 
t.typelem <> 0 AND t.typlen = -1 THEN 'UDT' || current_database() || '.' || n.nspname || '.' || udt.typname 
|| '.' || a.attnum ELSE NULL END, 
information_schema._pg_char_max_length(information_schema._pg_truetypid(a.*, t.*), 
information_schema._pg_truetypmod(a.*, t.*)), 
information_schema._pg_char_octet_length(information_schema._pg_truetypid(a.*, t.*), 
information_schema._pg_truetypmod(a.*, t.*)), 
information_schema._pg_numeric_precision(information_schema._pg_truetypid(a.*, t.*), 
information_schema._pg_truetypmod(a.*, t.*)), 
information_schema._pg_numeric_scale(information_schema._pg_truetypid(a.*, t.*), 
information_schema._pg_truetypmod(a.*, t.*)), 
information_schema._pg_datetime_precision(information_schema._pg_truetypid(a.*, t.*), 
information_schema._pg_truetypmod(a.*, 
 t.*)), N
 ULL, NULL , NULL, NULL, NULL, NULL FROM pg_type udt INNER JOIN pg_namespace n ON (udt.typnamespace=n.oid) 
INNER JOIN pg_attribute a ON (a.attrelid=udt.typrelid) INNER JOIN pg_type t ON (a.atttypid=t.oid) INNER JOIN 
pg_namespace nt ON (t.typnamespace = nt.oid) WHERE udt.typrelid != 0 AND (SELECT c.relkind = 'c' FROM 
pg_catalog.pg_class c WHERE c.oid = udt.typrelid)",
+
+       /* I_STMT_DOMAINS */
+       "SELECT pg_catalog.current_database(), nt.nspname, t.typname, CASE WHEN t.typelem <> 0 AND t.typlen = 
-1 THEN NULL ELSE coalesce (nbt.nspname || '.', '') || bt.typname END, CASE WHEN t.typelem <> 0 AND t.typlen 
= -1 THEN 'DOM' || current_database() || '.' || nt.nspname || '.' || t.typname ELSE NULL END, 'gchararray', 
information_schema._pg_char_max_length(t.typbasetype, t.typtypmod), 
information_schema._pg_char_octet_length(t.typbasetype, t.typtypmod),  NULL, NULL, NULL, NULL, NULL, NULL,  
information_schema._pg_numeric_precision(t.typbasetype, t.typtypmod), 
information_schema._pg_numeric_scale(t.typbasetype, t.typtypmod), t.typdefault, 
pg_catalog.obj_description(t.oid), CASE WHEN pg_catalog.pg_type_is_visible(t.oid) IS TRUE THEN t.typname ELSE 
coalesce (nt.nspname || '.', '') || t.typname END, coalesce (nt.nspname || '.', '') || t.typname, FALSE, 
o.rolname FROM pg_type t, pg_namespace nt, pg_type bt, pg_namespace nbt, pg_roles o WHERE t.typnamespace = 
nt.oid AND t.typbaset
 ype = bt
 .oid AND bt.typnamespace = nbt.oid AND t.typtype = 'd' AND o.oid=t.typowner AND 
pg_catalog.current_database() = ##cat::string AND nt.nspname = ##schema::string",
+
+       /* I_STMT_DOMAINS_ALL */
+       "SELECT pg_catalog.current_database(), nt.nspname, t.typname, CASE WHEN t.typelem <> 0 AND t.typlen = 
-1 THEN NULL ELSE coalesce (nbt.nspname || '.', '') || bt.typname END, CASE WHEN t.typelem <> 0 AND t.typlen 
= -1 THEN 'DOM' || current_database() || '.' || nt.nspname || '.' || t.typname ELSE NULL END, 'gchararray', 
information_schema._pg_char_max_length(t.typbasetype, t.typtypmod), 
information_schema._pg_char_octet_length(t.typbasetype, t.typtypmod),  NULL, NULL, NULL, NULL, NULL, NULL,  
information_schema._pg_numeric_precision(t.typbasetype, t.typtypmod), 
information_schema._pg_numeric_scale(t.typbasetype, t.typtypmod), t.typdefault, 
pg_catalog.obj_description(t.oid), CASE WHEN pg_catalog.pg_type_is_visible(t.oid) IS TRUE THEN t.typname ELSE 
coalesce (nt.nspname || '.', '') || t.typname END, coalesce (nt.nspname || '.', '') || t.typname, FALSE, 
o.rolname FROM pg_type t, pg_namespace nt, pg_type bt, pg_namespace nbt, pg_roles o WHERE t.typnamespace = 
nt.oid AND t.typbaset
 ype = bt
 .oid AND bt.typnamespace = nbt.oid AND t.typtype = 'd' AND o.oid=t.typowner",
+
+       /* I_STMT_DOMAINS_CONSTRAINTS */
+       "SELECT constraint_catalog, constraint_schema, constraint_name, domain_catalog, domain_schema, 
domain_name, NULL, CASE WHEN is_deferrable = 'YES' THEN TRUE ELSE FALSE END, CASE WHEN initially_deferred = 
'YES' THEN TRUE ELSE FALSE END FROM information_schema.domain_constraints WHERE domain_catalog = 
##cat::string AND domain_schema = ##schema::string AND domain_name = ##name::string",
+
+       /* I_STMT_DOMAINS_CONSTRAINTS_ALL */
+       "SELECT constraint_catalog, constraint_schema, constraint_name, domain_catalog, domain_schema, 
domain_name, NULL, CASE WHEN is_deferrable = 'YES' THEN TRUE ELSE FALSE END, CASE WHEN initially_deferred = 
'YES' THEN TRUE ELSE FALSE END FROM information_schema.domain_constraints",
+
+       /* I_STMT_VIEWS_COLUMNS */
+       "SELECT view_catalog, view_schema, view_name, table_catalog, table_schema, table_name, column_name 
FROM information_schema.view_column_usage WHERE view_catalog = ##cat::string AND view_schema = 
##schema::string AND view_name = ##name::string",
+
+       /* I_STMT_VIEWS_COLUMNS_ALL */
+       "SELECT view_catalog, view_schema, view_name, table_catalog, table_schema, table_name, column_name 
FROM information_schema.view_column_usage",
+
+       /* I_STMT_TRIGGERS */
+       "SELECT current_database(), n.nspname, t.tgname, em.text, current_database(), n.nspname, c.relname, 
\"substring\"(pg_get_triggerdef(t.oid), \"position\"(\"substring\"(pg_get_triggerdef(t.oid), 48), 'EXECUTE 
PROCEDURE') + 47) AS action_statement, CASE WHEN (t.tgtype & 1) = 1 THEN 'ROW' ELSE 'STATEMENT' END AS 
action_orientation, CASE WHEN (t.tgtype & 2) = 2 THEN 'BEFORE' ELSE 'AFTER' END AS condition_timing, 
pg_catalog.obj_description(t.oid), t.tgname, t.tgname FROM pg_namespace n, pg_class c, pg_trigger t, (( 
SELECT 4, 'INSERT' UNION ALL SELECT 8, 'DELETE') UNION ALL SELECT 16, 'UPDATE') em(num, text) WHERE n.oid = 
c.relnamespace AND c.oid = t.tgrelid AND (t.tgtype & em.num) <> 0 AND (t.tgconstraint = 0) AND NOT 
pg_is_other_temp_schema(n.oid) AND (pg_has_role(c.relowner, 'USAGE') OR has_table_privilege(c.oid, 'INSERT') 
OR has_table_privilege(c.oid, 'UPDATE') OR has_table_privilege(c.oid, 'DELETE') OR has_table_privilege(c.oid, 
'REFERENCES') OR has_table_privilege(c.oid, 'TR
 IGGER'))
  AND current_database() = ##cat::string AND n.nspname = ##schema::string AND c.relname = ##name::string",
+
+       /* I_STMT_TRIGGERS_ALL */
+       "SELECT current_database(), n.nspname, t.tgname, em.text, current_database(), n.nspname, c.relname, 
\"substring\"(pg_get_triggerdef(t.oid), \"position\"(\"substring\"(pg_get_triggerdef(t.oid), 48), 'EXECUTE 
PROCEDURE') + 47) AS action_statement, CASE WHEN (t.tgtype & 1) = 1 THEN 'ROW' ELSE 'STATEMENT' END AS 
action_orientation, CASE WHEN (t.tgtype & 2) = 2 THEN 'BEFORE' ELSE 'AFTER' END AS condition_timing, 
pg_catalog.obj_description(t.oid), t.tgname, t.tgname FROM pg_namespace n, pg_class c, pg_trigger t, (( 
SELECT 4, 'INSERT' UNION ALL SELECT 8, 'DELETE') UNION ALL SELECT 16, 'UPDATE') em(num, text) WHERE n.oid = 
c.relnamespace AND c.oid = t.tgrelid AND (t.tgtype & em.num) <> 0 AND NOT (t.tgconstraint = 0) AND NOT 
pg_is_other_temp_schema(n.oid) AND (pg_has_role(c.relowner, 'USAGE') OR has_table_privilege(c.oid, 'INSERT') 
OR has_table_privilege(c.oid, 'UPDATE') OR has_table_privilege(c.oid, 'DELETE') OR has_table_privilege(c.oid, 
'REFERENCES') OR has_table_privilege(c.oid,
  'TRIGGE
 R'))",
+
+       /* I_STMT_EL_TYPES_COL */
+       "SELECT 'COL' || current_database() || '.' || nc.nspname || '.' || c.relname || '.' || a.attnum, 
current_database(), nc.nspname, c.relname, 'TABLE_COL', coalesce (nbt.nspname || '.', '') || bt.typname, 
NULL, NULL, NULL FROM pg_attribute a, pg_class c, pg_namespace nc, pg_type t JOIN pg_namespace nt ON 
t.typnamespace = nt.oid LEFT JOIN (pg_type bt JOIN pg_namespace nbt ON bt.typnamespace = nbt.oid) ON 
t.typelem = bt.oid WHERE a.attrelid = c.oid AND a.atttypid = t.oid AND nc.oid = c.relnamespace AND NOT 
pg_is_other_temp_schema(nc.oid) AND a.attnum > 0 AND NOT a.attisdropped AND (c.relkind = ANY (ARRAY['r', 
'v'])) AND (pg_has_role(c.relowner, 'USAGE') OR has_table_privilege(c.oid, 'SELECT') OR 
has_table_privilege(c.oid, 'INSERT') OR has_table_privilege(c.oid, 'UPDATE') OR has_table_privilege(c.oid, 
'REFERENCES')) AND t.typelem <> 0 AND t.typlen = -1 AND 'COL' || current_database() || '.' || nc.nspname || 
'.' || c.relname || '.' || a.attnum = ##name::string",
+
+       /* I_STMT_EL_TYPES_DOM */
+       "SELECT 'DOM' || current_database() || '.' || nt.nspname || '.' || t.typname, current_database(), 
nt.nspname, t.typname, 'DOMAIN', coalesce (nbt.nspname || '.', '') || bt.typname, NULL, NULL, NULL FROM 
pg_type t, pg_namespace nt, pg_type bt, pg_namespace nbt WHERE t.typnamespace = nt.oid AND t.typelem = bt.oid 
AND bt.typnamespace = nbt.oid AND t.typtype = 'd' AND t.typlen = -1 AND 'DOM' || current_database() || '.' || 
nt.nspname || '.' || t.typname = ##name::string",
+
+       /* I_STMT_EL_TYPES_UDT */
+       "SELECT 'UDT' || current_database() || '.' || n.nspname || '.' || udt.typname || '.' || a.attnum, 
pg_catalog.current_database(), n.nspname, udt.typname, 'UDT_COL', coalesce (nbt.nspname || '.', '') || 
bt.typname, NULL, NULL, NULL FROM pg_type udt INNER JOIN pg_namespace n ON (udt.typnamespace=n.oid) INNER 
JOIN pg_attribute a ON (a.attrelid=udt.typrelid) INNER JOIN pg_type t ON (a.atttypid=t.oid) INNER JOIN 
pg_namespace nt ON (t.typnamespace = nt.oid), pg_type bt, pg_namespace nbt where udt.typrelid != 0 AND 
(SELECT c.relkind = 'c' FROM pg_catalog.pg_class c WHERE c.oid = udt.typrelid) AND t.typelem = bt.oid AND 
bt.typnamespace = nbt.oid AND t.typlen = -1 AND 'UDT' || current_database() || '.' || n.nspname || '.' || 
udt.typname || '.' || a.attnum = ##name::string",
+
+       /* I_STMT_EL_TYPES_ROUT_PAR */
+       "SELECT 'ROUP' || current_database() || '.' || ss.n_nspname || '.' || ((ss.proname || '_') || 
ss.p_oid) || '.' || (ss.x).n, current_database(), ss.n_nspname, ((ss.proname || '_') || ss.p_oid), 
'ROUTINE_PAR', coalesce (nbt.nspname || '.', '') || bt.typname, NULL, NULL, NULL FROM pg_type t, pg_type bt, 
pg_namespace nbt, ( SELECT n.nspname AS n_nspname, p.proname, p.oid AS p_oid, p.proargnames, p.proargmodes, 
information_schema._pg_expandarray(COALESCE(p.proallargtypes, p.proargtypes::oid[])) AS x FROM pg_namespace 
n, pg_proc p WHERE n.oid = p.pronamespace AND (pg_has_role(p.proowner, 'USAGE') OR 
has_function_privilege(p.oid, 'EXECUTE'))) ss WHERE t.oid = (ss.x).x AND bt.oid= t.typelem AND 
bt.typnamespace = nbt.oid AND t.typelem <> 0 AND t.typlen = -1 AND 'ROUP' || current_database() || '.' || 
ss.n_nspname || '.' || ((ss.proname || '_') || ss.p_oid) || '.' || (ss.x).n = ##name::string",
+
+       /* I_STMT_EL_TYPES_ROUT_COL */
+       "SELECT 'ROUC' || current_database() || '.' || ss.n_nspname || '.' || ((ss.proname || '_') || 
ss.p_oid) || '.' || (ss.x).n, current_database(), ss.n_nspname, ((ss.proname || '_') || ss.p_oid), 
'ROUTINE_COL', CASE WHEN at.typelem <> 0 AND at.typlen = -1 THEN 'array_spec' ELSE coalesce (ant.nspname || 
'.', '') || at.typname END, CASE WHEN at.typelem <> 0 AND at.typlen = -1 THEN 'ARR' || at.typelem ELSE NULL 
END, NULL, NULL FROM pg_type t, pg_namespace nt, ( SELECT n.nspname AS n_nspname, p.proname, p.oid AS p_oid, 
p.proargnames, p.proargmodes, information_schema._pg_expandarray(COALESCE(p.proallargtypes, 
p.proargtypes::oid[])) AS x FROM pg_namespace n, pg_proc p WHERE n.oid = p.pronamespace AND 
(pg_has_role(p.proowner, 'USAGE') OR has_function_privilege(p.oid, 'EXECUTE'))) ss, pg_type at, pg_namespace 
ant WHERE t.oid = (ss.x).x AND t.typnamespace = nt.oid AND at.oid = t.typelem AND at.typnamespace = ant.oid 
AND (ss.proargmodes[(ss.x).n] = 'o' OR ss.proargmodes[(ss.x).n] = 'b'
 ) AND 'R
 OUC' || current_database() || '.' || ss.n_nspname || '.' || ((ss.proname || '_') || ss.p_oid) || '.' || 
(ss.x).n = ##name::string",
+
+       /* I_STMT_EL_TYPES_ALL */
+       "SELECT 'UDT' || current_database() || '.' || n.nspname || '.' || udt.typname || '.' || a.attnum, 
pg_catalog.current_database(), n.nspname, udt.typname, 'UDT_COL', coalesce (nbt.nspname || '.', '') || 
bt.typname, NULL, NULL, NULL FROM pg_type udt INNER JOIN pg_namespace n ON (udt.typnamespace=n.oid) INNER 
JOIN pg_attribute a ON (a.attrelid=udt.typrelid) INNER JOIN pg_type t ON (a.atttypid=t.oid) INNER JOIN 
pg_namespace nt ON (t.typnamespace = nt.oid), pg_type bt, pg_namespace nbt where udt.typrelid != 0 AND 
(SELECT c.relkind = 'c' FROM pg_catalog.pg_class c WHERE c.oid = udt.typrelid) AND t.typelem = bt.oid AND 
bt.typnamespace = nbt.oid AND t.typlen = -1 "
+       "UNION SELECT 'DOM' || current_database() || '.' || nt.nspname || '.' || t.typname, 
current_database(), nt.nspname, t.typname, 'DOMAIN', coalesce (nbt.nspname || '.', '') || bt.typname, NULL, 
NULL, NULL FROM pg_type t, pg_namespace nt, pg_type bt, pg_namespace nbt WHERE t.typnamespace = nt.oid AND 
t.typelem = bt.oid AND bt.typnamespace = nbt.oid AND t.typtype = 'd' AND t.typlen = -1 "
+       "UNION SELECT 'COL' || current_database() || '.' || nc.nspname || '.' || c.relname || '.' || 
a.attnum, current_database(), nc.nspname, c.relname, 'TABLE_COL', coalesce (nbt.nspname || '.', '') || 
bt.typname, NULL, NULL, NULL FROM pg_attribute a, pg_class c, pg_namespace nc, pg_type t JOIN pg_namespace nt 
ON t.typnamespace = nt.oid LEFT JOIN (pg_type bt JOIN pg_namespace nbt ON bt.typnamespace = nbt.oid) ON 
t.typelem = bt.oid WHERE a.attrelid = c.oid AND a.atttypid = t.oid AND nc.oid = c.relnamespace AND NOT 
pg_is_other_temp_schema(nc.oid) AND a.attnum > 0 AND NOT a.attisdropped AND (c.relkind = ANY (ARRAY['r', 
'v'])) AND (pg_has_role(c.relowner, 'USAGE') OR has_table_privilege(c.oid, 'SELECT') OR 
has_table_privilege(c.oid, 'INSERT') OR has_table_privilege(c.oid, 'UPDATE') OR has_table_privilege(c.oid, 
'REFERENCES')) AND t.typelem <> 0 AND t.typlen = -1 "
+       "UNION SELECT 'ROUP' || current_database() || '.' || ss.n_nspname || '.' || ((ss.proname || '_') || 
ss.p_oid) || '.' || (ss.x).n, current_database(), ss.n_nspname, ((ss.proname || '_') || ss.p_oid), 
'ROUTINE_PAR', coalesce (nbt.nspname || '.', '') || bt.typname, NULL, NULL, NULL FROM pg_type t, pg_type bt, 
pg_namespace nbt, ( SELECT n.nspname AS n_nspname, p.proname, p.oid AS p_oid, p.proargnames, p.proargmodes, 
information_schema._pg_expandarray(COALESCE(p.proallargtypes, p.proargtypes::oid[])) AS x FROM pg_namespace 
n, pg_proc p WHERE n.oid = p.pronamespace AND (pg_has_role(p.proowner, 'USAGE') OR 
has_function_privilege(p.oid, 'EXECUTE'))) ss WHERE t.oid = (ss.x).x AND bt.oid= t.typelem AND 
bt.typnamespace = nbt.oid AND t.typelem <> 0 AND t.typlen = -1 "
+       "UNION SELECT 'ROUC' || current_database() || '.' || ss.n_nspname || '.' || ((ss.proname || '_') || 
ss.p_oid) || '.' || (ss.x).n, current_database(), ss.n_nspname, ((ss.proname || '_') || ss.p_oid), 
'ROUTINE_COL', CASE WHEN at.typelem <> 0 AND at.typlen = -1 THEN 'array_spec' ELSE coalesce (ant.nspname || 
'.', '') || at.typname END, CASE WHEN at.typelem <> 0 AND at.typlen = -1 THEN 'ARR' || at.typelem ELSE NULL 
END, NULL, NULL FROM pg_type t, pg_namespace nt, ( SELECT n.nspname AS n_nspname, p.proname, p.oid AS p_oid, 
p.proargnames, p.proargmodes, information_schema._pg_expandarray(COALESCE(p.proallargtypes, 
p.proargtypes::oid[])) AS x FROM pg_namespace n, pg_proc p WHERE n.oid = p.pronamespace AND 
(pg_has_role(p.proowner, 'USAGE') OR has_function_privilege(p.oid, 'EXECUTE'))) ss, pg_type at, pg_namespace 
ant WHERE t.oid = (ss.x).x AND t.typnamespace = nt.oid AND at.oid = t.typelem AND at.typnamespace = ant.oid 
AND (ss.proargmodes[(ss.x).n] = 'o' OR ss.proargmodes[(ss.x).n]
  = 'b')"
 ,
+
+       /* I_STMT_ROUTINES_ALL */
+       "SELECT current_database(), n.nspname, ((p.proname || '_') || p.oid), current_database(), n.nspname, 
p.proname, CASE WHEN p.prokind = 'a' THEN 'AGGREGATE' ELSE 'FUNCTION' END, CASE WHEN t.typelem <> 0 AND 
t.typlen = -1 THEN 'ROUC' || current_database() || '.' || n.nspname || '.' || p.proname || '.' || p.oid ELSE 
coalesce (nt.nspname || '.', '') || t.typname END AS rettype, p.proretset, p.pronargs, CASE WHEN l.lanname = 
'sql' THEN 'SQL' ELSE 'EXTERNAL' END, CASE WHEN pg_has_role(p.proowner, 'USAGE') THEN p.prosrc ELSE NULL END, 
CASE WHEN l.lanname = 'c' THEN p.prosrc ELSE NULL END, upper(l.lanname) AS external_language, 'GENERAL' AS 
parameter_style, CASE WHEN p.provolatile = 'i' THEN TRUE ELSE FALSE END, 'MODIFIES' AS sql_data_access, CASE 
WHEN p.proisstrict THEN TRUE ELSE FALSE END, pg_catalog.obj_description(p.oid), CASE WHEN 
pg_catalog.pg_function_is_visible(p.oid) IS TRUE THEN p.proname ELSE coalesce (n.nspname || '.', '') || 
p.proname END, coalesce (n.nspname || '.', ''
 ) || p.p
 roname, o.rolname FROM pg_namespace n, pg_proc p, pg_language l, pg_type t, pg_namespace nt, pg_roles o 
WHERE n.oid = p.pronamespace AND p.prolang = l.oid AND p.prorettype = t.oid AND t.typnamespace = nt.oid AND 
(pg_has_role(p.proowner, 'USAGE') OR has_function_privilege(p.oid, 'EXECUTE')) AND o.oid=p.proowner",
+
+       /* I_STMT_ROUTINES */
+       "SELECT current_database(), n.nspname, ((p.proname || '_') || p.oid), current_database(), n.nspname, 
p.proname, CASE WHEN p.prokind = 'a' THEN 'AGGREGATE' ELSE 'FUNCTION' END, CASE WHEN t.typelem <> 0 AND 
t.typlen = -1 THEN 'ROUC' || current_database() || '.' || n.nspname || '.' || p.proname || '.' || p.oid ELSE 
coalesce (nt.nspname || '.', '') || t.typname END AS rettype, p.proretset, p.pronargs, CASE WHEN l.lanname = 
'sql' THEN 'SQL' ELSE 'EXTERNAL' END, CASE WHEN pg_has_role(p.proowner, 'USAGE') THEN p.prosrc ELSE NULL END, 
CASE WHEN l.lanname = 'c' THEN p.prosrc ELSE NULL END, upper(l.lanname) AS external_language, 'GENERAL' AS 
parameter_style, CASE WHEN p.provolatile = 'i' THEN TRUE ELSE FALSE END, 'MODIFIES' AS sql_data_access, CASE 
WHEN p.proisstrict THEN TRUE ELSE FALSE END, pg_catalog.obj_description(p.oid), CASE WHEN 
pg_catalog.pg_function_is_visible(p.oid) IS TRUE THEN p.proname ELSE coalesce (n.nspname || '.', '') || 
p.proname END, coalesce (n.nspname || '.', ''
 ) || p.p
 roname, o.rolname FROM pg_namespace n, pg_proc p, pg_language l, pg_type t, pg_namespace nt, pg_roles o 
WHERE current_database() = ##cat::string AND n.nspname = ##schema::string AND n.oid = p.pronamespace AND 
p.prolang = l.oid AND p.prorettype = t.oid AND t.typnamespace = nt.oid AND (pg_has_role(p.proowner, 'USAGE') 
OR has_function_privilege(p.oid, 'EXECUTE')) AND o.oid=p.proowner",
+
+       /* I_STMT_ROUTINES_ONE */
+       "SELECT current_database(), n.nspname, ((p.proname || '_') || p.oid), current_database(), n.nspname, 
p.proname, CASE WHEN p.prokind = 'a' THEN 'AGGREGATE' ELSE 'FUNCTION' END, CASE WHEN t.typelem <> 0 AND 
t.typlen = -1 THEN 'ROUC' || current_database() || '.' || n.nspname || '.' || p.proname || '.' || p.oid ELSE 
coalesce (nt.nspname || '.', '') || t.typname END AS rettype, p.proretset, p.pronargs, CASE WHEN l.lanname = 
'sql' THEN 'SQL' ELSE 'EXTERNAL' END, CASE WHEN pg_has_role(p.proowner, 'USAGE') THEN p.prosrc ELSE NULL END, 
CASE WHEN l.lanname = 'c' THEN p.prosrc ELSE NULL END, upper(l.lanname) AS external_language, 'GENERAL' AS 
parameter_style, CASE WHEN p.provolatile = 'i' THEN TRUE ELSE FALSE END, 'MODIFIES' AS sql_data_access, CASE 
WHEN p.proisstrict THEN TRUE ELSE FALSE END, pg_catalog.obj_description(p.oid), CASE WHEN 
pg_catalog.pg_function_is_visible(p.oid) IS TRUE THEN p.proname ELSE coalesce (n.nspname || '.', '') || 
p.proname END, coalesce (n.nspname || '.', ''
 ) || p.p
 roname, o.rolname FROM pg_namespace n, pg_proc p, pg_language l, pg_type t, pg_namespace nt, pg_roles o 
WHERE current_database() = ##cat::string AND n.nspname = ##schema::string AND ((p.proname || '_') || p.oid) = 
##name::string AND n.oid = p.pronamespace AND p.prolang = l.oid AND p.prorettype = t.oid AND t.typnamespace = 
nt.oid AND (pg_has_role(p.proowner, 'USAGE') OR has_function_privilege(p.oid, 'EXECUTE')) AND 
o.oid=p.proowner",
+
+       /* I_STMT_ROUTINE_PAR_ALL */
+       "SELECT current_database(), ss.n_nspname, ((ss.proname || '_') || ss.p_oid), (ss.x).n, CASE WHEN 
ss.proargmodes IS NULL THEN 'IN' WHEN ss.proargmodes[(ss.x).n] = 'i' THEN 'IN' WHEN ss.proargmodes[(ss.x).n] 
= 'o' THEN 'OUT' WHEN ss.proargmodes[(ss.x).n] = 'b' THEN 'INOUT' ELSE NULL END, 
NULLIF(ss.proargnames[(ss.x).n], ''), CASE WHEN t.typelem <> 0 AND t.typlen = -1 THEN 'array_spec' ELSE 
coalesce (nt.nspname || '.', '') || t.typname END, CASE WHEN t.typelem <> 0 AND t.typlen = -1 THEN 'ROUP' || 
current_database() || '.' || ss.n_nspname || '.' || ((ss.proname || '_') || ss.p_oid) || '.' || (ss.x).n ELSE 
NULL END FROM pg_type t, pg_namespace nt, ( SELECT n.nspname AS n_nspname, p.proname, p.oid AS p_oid, 
p.proargnames, p.proargmodes, information_schema._pg_expandarray(COALESCE(p.proallargtypes, 
p.proargtypes::oid[])) AS x FROM pg_namespace n, pg_proc p WHERE n.oid = p.pronamespace AND 
(pg_has_role(p.proowner, 'USAGE') OR has_function_privilege(p.oid, 'EXECUTE'))) ss WHERE ((s
 s.proarg
 modes[(ss.x).n] != 't' AND ss.proargmodes[(ss.x).n] != 'v') OR ss.proargmodes[(ss.x).n] IS NULL) AND t.oid = 
(ss.x).x AND t.typnamespace = nt.oid",
+
+       /* I_STMT_ROUTINE_PAR */
+       "SELECT current_database(), ss.n_nspname, ((ss.proname || '_') || ss.p_oid), (ss.x).n, CASE WHEN 
ss.proargmodes IS NULL THEN 'IN' WHEN ss.proargmodes[(ss.x).n] = 'i' THEN 'IN' WHEN ss.proargmodes[(ss.x).n] 
= 'o' THEN 'OUT' WHEN ss.proargmodes[(ss.x).n] = 'b' THEN 'INOUT' ELSE NULL END, 
NULLIF(ss.proargnames[(ss.x).n], ''), CASE WHEN t.typelem <> 0 AND t.typlen = -1 THEN 'array_spec' ELSE 
coalesce (nt.nspname || '.', '') || t.typname END, CASE WHEN t.typelem <> 0 AND t.typlen = -1 THEN 'ROUP' || 
current_database() || '.' || ss.n_nspname || '.' || ((ss.proname || '_') || ss.p_oid) || '.' || (ss.x).n ELSE 
NULL END FROM pg_type t, pg_namespace nt, ( SELECT n.nspname AS n_nspname, p.proname, p.oid AS p_oid, 
p.proargnames, p.proargmodes, information_schema._pg_expandarray(COALESCE(p.proallargtypes, 
p.proargtypes::oid[])) AS x FROM pg_namespace n, pg_proc p WHERE n.oid = p.pronamespace AND 
(pg_has_role(p.proowner, 'USAGE') OR has_function_privilege(p.oid, 'EXECUTE'))) ss WHERE ((s
 s.proarg
 modes[(ss.x).n] != 't' AND ss.proargmodes[(ss.x).n] != 'v') OR ss.proargmodes[(ss.x).n] IS NULL) AND t.oid = 
(ss.x).x AND t.typnamespace = nt.oid AND current_database() = ##cat::string AND ss.n_nspname = 
##schema::string AND ((ss.proname || '_') || ss.p_oid) = ##name::string",
+
+       /* I_STMT_ROUTINE_COL_ALL */
+       "SELECT current_database(), ss.n_nspname, ((ss.proname || '_') || ss.p_oid), 
NULLIF(ss.proargnames[(ss.x).n], ''), (ss.x).n, CASE WHEN t.typelem <> 0 AND t.typlen = -1 THEN 'array_spec' 
ELSE coalesce (nt.nspname || '.', '') || t.typname END, CASE WHEN t.typelem <> 0 AND t.typlen = -1 THEN 
'ROUC' || current_database() || '.' || ss.n_nspname || '.' || ((ss.proname || '_') || ss.p_oid) || '.' || 
(ss.x).n ELSE NULL END FROM pg_type t, pg_namespace nt, ( SELECT n.nspname AS n_nspname, p.proname, p.oid AS 
p_oid, p.proargnames, p.proargmodes, information_schema._pg_expandarray(COALESCE(p.proallargtypes, 
p.proargtypes::oid[])) AS x FROM pg_namespace n, pg_proc p WHERE n.oid = p.pronamespace AND 
(pg_has_role(p.proowner, 'USAGE') OR has_function_privilege(p.oid, 'EXECUTE'))) ss WHERE t.oid = (ss.x).x AND 
t.typnamespace = nt.oid AND (ss.proargmodes[(ss.x).n] = 'o' OR ss.proargmodes[(ss.x).n] = 'b') ORDER BY 1, 2, 
3, 4, 5",
+
+       /* I_STMT_ROUTINE_COL */
+       "SELECT current_database(), ss.n_nspname, ((ss.proname || '_') || ss.p_oid), 
NULLIF(ss.proargnames[(ss.x).n], '') AS column_name, (ss.x).n AS ordinal_position, CASE WHEN t.typelem <> 0 
AND t.typlen = -1 THEN 'array_spec' ELSE coalesce (nt.nspname || '.', '') || t.typname END, CASE WHEN 
t.typelem <> 0 AND t.typlen = -1 THEN 'ROUC' || current_database() || '.' || ss.n_nspname || '.' || 
((ss.proname || '_') || ss.p_oid) || '.' || (ss.x).n ELSE NULL END FROM pg_type t, pg_namespace nt, ( SELECT 
n.nspname AS n_nspname, p.proname, p.oid AS p_oid, p.proargnames, p.proargmodes, 
information_schema._pg_expandarray(COALESCE(p.proallargtypes, p.proargtypes::oid[])) AS x FROM pg_namespace 
n, pg_proc p WHERE n.oid = p.pronamespace AND (pg_has_role(p.proowner, 'USAGE') OR 
has_function_privilege(p.oid, 'EXECUTE'))) ss WHERE t.oid = (ss.x).x AND t.typnamespace = nt.oid AND 
(ss.proargmodes[(ss.x).n] = 'o' OR ss.proargmodes[(ss.x).n] = 'b') AND current_database() = ##cat::string AND 
ss.n_nspn
 ame = ##
 schema::string AND ((ss.proname || '_') || ss.p_oid) = ##name::string AND column_name = ##name2::string AND 
ordinal_position = ##name3::string ORDER BY 1, 2, 3, 4, 5",
+
+       /* I_STMT_INDEXES */
+       "SELECT current_database() AS index_catalog, nc2.nspname AS index_schema, c2.relname AS index_name, 
current_database() AS table_catalog, nc.nspname AS table_schema, c.relname AS table_name, i.indisunique, 
pg_get_indexdef (i.indexrelid, 0, false), NULL, NULL, o.rolname, pg_catalog.obj_description (c2.oid), 
i.indexrelid FROM pg_catalog.pg_class c INNER JOIN pg_namespace nc ON (c.relnamespace = nc.oid), 
pg_catalog.pg_class c2 INNER JOIN pg_namespace nc2 ON (c2.relnamespace = nc2.oid) LEFT JOIN pg_roles o ON 
(o.oid=c2.relowner), pg_catalog.pg_index i WHERE c.oid = i.indrelid AND i.indexrelid = c2.oid AND NOT 
i.indisprimary AND pg_catalog.pg_table_is_visible(c.oid) AND nc.nspname = ##schema::string AND c.relname = 
##name::string ORDER BY c.relname",
+
+       /* I_STMT_INDEXES_ALL */
+       "SELECT current_database() AS index_catalog, nc2.nspname AS index_schema, c2.relname AS index_name, 
current_database() AS table_catalog, nc.nspname AS table_schema, c.relname AS table_name, i.indisunique, 
pg_get_indexdef (i.indexrelid, 0, false), NULL, NULL, o.rolname, pg_catalog.obj_description (c2.oid), 
i.indexrelid FROM pg_catalog.pg_class c INNER JOIN pg_namespace nc ON (c.relnamespace = nc.oid), 
pg_catalog.pg_class c2 INNER JOIN pg_namespace nc2 ON (c2.relnamespace = nc2.oid) LEFT JOIN pg_roles o ON 
(o.oid=c2.relowner), pg_catalog.pg_index i WHERE c.oid = i.indrelid AND i.indexrelid = c2.oid AND NOT 
i.indisprimary AND pg_catalog.pg_table_is_visible(c.oid) ORDER BY c.relname",
+
+       /* I_STMT_INDEXES_NAMED */
+       "SELECT current_database() AS index_catalog, nc2.nspname AS index_schema, c2.relname AS index_name, 
current_database() AS table_catalog, nc.nspname AS table_schema, c.relname AS table_name, i.indisunique, 
pg_get_indexdef (i.indexrelid, 0, false), NULL, NULL, o.rolname, pg_catalog.obj_description (c2.oid), 
i.indexrelid FROM pg_catalog.pg_class c INNER JOIN pg_namespace nc ON (c.relnamespace = nc.oid), 
pg_catalog.pg_class c2 INNER JOIN pg_namespace nc2 ON (c2.relnamespace = nc2.oid) LEFT JOIN pg_roles o ON 
(o.oid=c2.relowner), pg_catalog.pg_index i WHERE c.oid = i.indrelid AND i.indexrelid = c2.oid AND NOT 
i.indisprimary AND pg_catalog.pg_table_is_visible(c.oid) AND nc.nspname = ##schema::string AND c.relname = 
##name::string AND c2.relname = ##name2::string ORDER BY c.relname",
+
+       /* I_STMT_INDEXES_COLUMNS_GET_ALL_INDEXES */
+       "SELECT i.indexrelid FROM pg_catalog.pg_class c, pg_catalog.pg_index i WHERE c.oid = i.indrelid AND 
NOT i.indisprimary AND pg_catalog.pg_table_is_visible(c.oid)",
+
+       /* I_STMT_INDEXES_COLUMNS_GET_NAMED_INDEXES */
+       "SELECT i.indexrelid FROM pg_catalog.pg_class c INNER JOIN pg_namespace nc ON (c.relnamespace = 
nc.oid), pg_catalog.pg_index i, pg_catalog.pg_class c2 INNER JOIN pg_namespace nc2 ON (c2.relnamespace = 
nc2.oid) WHERE c.oid = i.indrelid AND NOT i.indisprimary AND pg_catalog.pg_table_is_visible(c.oid) AND 
i.indexrelid = c2.oid AND c.relname = ##name::string AND nc.nspname = ##schema::string AND 
c2.relname=##name2::string",
+
+       /* I_STMT_INDEXES_COLUMNS_FOR_INDEX */
+       "SELECT current_database() AS index_catalog, nc2.nspname AS index_schema, c2.relname AS index_name, 
current_database() AS table_catalog, nc.nspname AS table_schema, c.relname AS table_name, a.attname, NULL, 
(ss.a).n FROM pg_catalog.pg_index i, (SELECT information_schema._pg_expandarray(indkey) AS a FROM 
pg_catalog.pg_index WHERE indexrelid = ##oid::guint) ss, pg_catalog.pg_class c INNER JOIN pg_namespace nc ON 
(c.relnamespace = nc.oid) INNER JOIN pg_catalog.pg_attribute a ON (a.attrelid = c.oid), pg_catalog.pg_class 
c2 INNER JOIN pg_namespace nc2 ON (c2.relnamespace = nc2.oid) WHERE i.indexrelid = ##oid::guint AND (ss.a).x 
!= 0 AND a.attnum = (ss.a).x AND c.oid = i.indrelid AND i.indexrelid = c2.oid AND 
pg_catalog.pg_table_is_visible(c.oid) UNION SELECT current_database() AS index_catalog, nc2.nspname AS 
index_schema, c2.relname AS index_name, current_database() AS table_catalog, nc.nspname AS table_schema, 
c.relname AS table_name, NULL, pg_get_indexdef (i.indexrelid, (ss.a
 ).n, fal
 se), (ss.a).n FROM pg_catalog.pg_index i, (SELECT information_schema._pg_expandarray(indkey) AS a FROM 
pg_catalog.pg_index WHERE indexrelid = ##oid::guint) ss, pg_catalog.pg_class c INNER JOIN pg_namespace nc ON 
(c.relnamespace = nc.oid), pg_catalog.pg_class c2 INNER JOIN pg_namespace nc2 ON (c2.relnamespace = nc2.oid) 
WHERE i.indexrelid = ##oid::guint AND (ss.a).x = 0 AND c.oid = i.indrelid AND i.indexrelid = c2.oid AND 
pg_catalog.pg_table_is_visible(c.oid) order by 9"
+};
+
 /*
  * global static values, and
  * predefined statements' GdaStatement, all initialized in _gda_postgres_provider_meta_init()
@@ -1710,6 +1880,7 @@ _gda_postgres_meta__routines (G_GNUC_UNUSED GdaServerProvider *prov, GdaConnecti
 {
        GdaDataModel *model;
        gboolean retval;
+       GdaStatement *stmt = NULL;
 
        /* check correct postgres server version */
        GdaPostgresReuseable *rdata;
@@ -1720,23 +1891,15 @@ _gda_postgres_meta__routines (G_GNUC_UNUSED GdaServerProvider *prov, GdaConnecti
                /* nothing for this version of PostgreSQL */
                return TRUE;
        }
-       if (!gda_connection_statement_prepare (cnc, internal_stmt[I_STMT_ROUTINES_ALL], error)) {
-               return FALSE;
-       }
-#ifdef GDA_DEBUG
-               gchar *st = gda_connection_statement_to_sql (cnc, internal_stmt[I_STMT_ROUTINES_ALL], NULL, 
GDA_STATEMENT_SQL_PARAMS_AS_VALUES, NULL, error);
-               g_message ("Provider: %s", gda_connection_get_provider_name (cnc));
-               if (st == NULL) {
-                       g_warning ("Error rendering Routines SQL For ALL Routines: %s",
-                                                                (*error) && (*error)->message ? 
(*error)->message : "No error set");
-                       g_clear_error (error);
-               } else {
-                       g_message ("Routine SQL : %s", st);
-                       g_free (st);
+       stmt = internal_stmt[I_STMT_ROUTINES_ALL];
+       if (rdata->version_float >= 11.0) {
+               stmt = gda_connection_parse_sql_string (cnc, internal_sql_11[I_STMT_ROUTINES_ALL], NULL, 
error);
+               if (stmt == NULL) {
+                       return FALSE;
                }
-#endif
+       }
        model = gda_connection_statement_execute_select_full (cnc,
-                                                             internal_stmt[I_STMT_ROUTINES_ALL],
+                                                             stmt,
                                                              NULL,
                                                              GDA_STATEMENT_MODEL_RANDOM_ACCESS,
                                                              _col_types_routines, error);
@@ -1758,6 +1921,7 @@ _gda_postgres_meta_routines (G_GNUC_UNUSED GdaServerProvider *prov, GdaConnectio
                             const GValue *routine_name_n)
 {
        GdaDataModel *model;
+       GdaStatement *stmt = NULL;
        gboolean retval = TRUE;
 
        /* check correct postgres server version */
@@ -1777,36 +1941,28 @@ _gda_postgres_meta_routines (G_GNUC_UNUSED GdaServerProvider *prov, GdaConnectio
        if (routine_name_n) {
                if (! gda_holder_set_value (gda_set_get_holder (i_set, "name"), routine_name_n, error))
                        return FALSE;
-#ifdef GDA_DEBUG
-               gchar *st = gda_connection_statement_to_sql (cnc, internal_stmt[I_STMT_ROUTINES_ONE], i_set, 
GDA_STATEMENT_SQL_PARAMS_AS_VALUES, NULL, error);
-               if (st == NULL) {
-                       g_warning ("Error rendering Routines SQL For ONE Routine: %s",
-                                                                (*error) && (*error)->message ? 
(*error)->message : "No error set");
-                       g_clear_error (error);
-               } else {
-                       g_message ("Routine SQL: %s", st);
-                       g_free (st);
+               stmt = internal_stmt[I_STMT_ROUTINES_ONE];
+               if (rdata->version_float >= 11.0) {
+                       stmt = gda_connection_parse_sql_string (cnc, internal_sql_11[I_STMT_ROUTINES_ONE], 
NULL, error);
+                       if (stmt == NULL) {
+                               return FALSE;
+                       }
                }
-#endif
                model = gda_connection_statement_execute_select_full (cnc,
-                                                                     internal_stmt[I_STMT_ROUTINES_ONE],
+                                                                     stmt,
                                                                      i_set,
                                                                      GDA_STATEMENT_MODEL_RANDOM_ACCESS,
                                                                      _col_types_routines, error);
        } else {
-#ifdef GDA_DEBUG
-               gchar *st = gda_connection_statement_to_sql (cnc, internal_stmt[I_STMT_ROUTINES], i_set, 
GDA_STATEMENT_SQL_PARAMS_AS_VALUES, NULL, error);
-               if (st == NULL) {
-                       g_warning ("Error rendering Routines SQL  For Routines In Catalog: %s",
-                                                    (*error) && (*error)->message ? (*error)->message : "No 
error set");
-                       g_clear_error (error);
-               } else {
-                       g_message ("Routine SQL: %s", st);
-                       g_free (st);
+               stmt = internal_stmt[I_STMT_ROUTINES];
+               if (rdata->version_float >= 11.0) {
+                       stmt = gda_connection_parse_sql_string (cnc, internal_sql_11[I_STMT_ROUTINES], NULL, 
error);
+                       if (stmt == NULL) {
+                               return FALSE;
+                       }
                }
-#endif
                model = gda_connection_statement_execute_select_full (cnc,
-                                                                     internal_stmt[I_STMT_ROUTINES],
+                                                                     stmt,
                                                                      i_set,
                                                                      GDA_STATEMENT_MODEL_RANDOM_ACCESS,
                                                                      _col_types_routines, error);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]