- TABLES_QUERY =
<<-SQL.freeze
SELECT table_name
FROM information_schema.tables
WHERE table_type = 'BASE TABLE'
AND table_schema = 'public'
SQL
- COLUMNS_QUERY =
<<-SQL.freeze
SELECT c.table_name,
c.column_name AS name,
c.ordinal_position AS pos,
c.column_default AS default,
c.is_nullable AS null,
c.data_type AS type,
c.is_identity,
c.udt_name AS custom_type_name,
c.character_maximum_length AS char_length,
c.numeric_precision AS num_precision,
c.numeric_scale AS num_scale,
c.datetime_precision AS dt_precision,
c.interval_type,
e.data_type AS element_type,
e.udt_name AS element_custom_type_name
FROM information_schema.columns AS c
LEFT JOIN information_schema.element_types AS e
ON e.object_catalog = c.table_catalog
AND e.object_schema = c.table_schema
AND e.object_name = c.table_name
AND e.object_type = 'TABLE'
AND e.collection_type_identifier = c.dtd_identifier
WHERE c.table_schema = 'public'
SQL
- INDEXES_QUERY =
<<-SQL.freeze
SELECT table_rel.relname AS table_name,
pg_class.relname AS name,
indkey AS column_positions,
indisprimary AS primary,
indisunique AS unique,
indoption AS index_options,
pg_get_expr(indpred, indrelid, true) AS condition,
amname AS index_type,
indexrelid AS index_oid
FROM pg_class, pg_index
LEFT JOIN pg_opclass
ON pg_opclass.oid = ANY(pg_index.indclass::int[])
LEFT JOIN pg_am
ON pg_am.oid = pg_opclass.opcmethod
JOIN pg_class AS table_rel
ON table_rel.oid = pg_index.indrelid
JOIN pg_namespace
ON pg_namespace.oid = table_rel.relnamespace
WHERE pg_class.oid = pg_index.indexrelid
AND pg_namespace.nspname = 'public'
GROUP BY table_name, name, column_positions, indisprimary, indisunique, index_options, condition, index_type, index_oid
SQL
- EXPRESSION_INDEXES_QUERY =
<<-SQL.freeze
WITH index_ids AS (SELECT unnest(?) AS index_id),
elements AS (SELECT unnest(?) AS element)
SELECT index_id,
array_agg(pg_get_indexdef(index_id, element, 't')) AS definitions
FROM index_ids, elements
GROUP BY index_id;
SQL
- CONSTRAINTS_QUERY =
<<-SQL.freeze
SELECT owner_table.relname AS table_name,
constr.conname AS name,
pg_get_expr(conbin, conrelid, true) AS condition,
referenced_table.relname AS referenced,
conkey,
confkey,
confupdtype AS on_update,
confdeltype AS on_delete,
condeferrable AS deferrable,
constr.contype AS type
FROM pg_constraint AS constr
JOIN pg_class AS owner_table
ON owner_table.oid = constr.conrelid
LEFT JOIN pg_class AS referenced_table
ON referenced_table.oid = constr.confrelid
WHERE contype IN ('c', 'f');
SQL
- ENUMS_QUERY =
<<-SQL.freeze
SELECT t.typname AS name,
array_agg(e.enumlabel ORDER BY e.enumsortorder) AS values
FROM pg_enum AS e
JOIN pg_type AS t
ON t.oid = e.enumtypid
GROUP BY name
SQL
- EXTENSIONS_QUERY =
<<-SQL.freeze
SELECT extname
FROM pg_extension
WHERE extname != 'plpgsql'
SQL
- VERSION =
'0.2'