2018-12-19 13:41:06 +03:00
|
|
|
select
|
|
|
|
coalesce(columns.columns, '[]') as columns,
|
2019-03-22 10:08:42 +03:00
|
|
|
coalesce(pk.columns, '[]') as primary_key_columns,
|
2018-12-19 13:41:06 +03:00
|
|
|
coalesce(constraints.constraints, '[]') as constraints,
|
|
|
|
coalesce(views.view_info, 'null') as view_info
|
|
|
|
from
|
|
|
|
information_schema.tables as tables
|
|
|
|
left outer join (
|
|
|
|
select
|
|
|
|
c.table_schema,
|
|
|
|
c.table_name,
|
|
|
|
json_agg(
|
|
|
|
json_build_object(
|
|
|
|
'name',
|
|
|
|
column_name,
|
|
|
|
'type',
|
|
|
|
udt_name,
|
|
|
|
'is_nullable',
|
|
|
|
is_nullable :: boolean
|
|
|
|
)
|
|
|
|
) as columns
|
|
|
|
from
|
|
|
|
information_schema.columns c
|
|
|
|
group by
|
|
|
|
c.table_schema,
|
|
|
|
c.table_name
|
|
|
|
) columns on (
|
|
|
|
tables.table_schema = columns.table_schema
|
|
|
|
AND tables.table_name = columns.table_name
|
|
|
|
)
|
2019-03-22 10:08:42 +03:00
|
|
|
left outer join (
|
|
|
|
select * from hdb_catalog.hdb_primary_key
|
|
|
|
) pk on (
|
|
|
|
tables.table_schema = pk.table_schema
|
|
|
|
AND tables.table_name = pk.table_name
|
|
|
|
)
|
2018-12-19 13:41:06 +03:00
|
|
|
left outer join (
|
|
|
|
select
|
2019-03-22 10:08:42 +03:00
|
|
|
c.table_schema,
|
|
|
|
c.table_name,
|
|
|
|
json_agg(constraint_name) as constraints
|
2018-12-19 13:41:06 +03:00
|
|
|
from
|
2019-03-22 10:08:42 +03:00
|
|
|
information_schema.table_constraints c
|
|
|
|
where
|
|
|
|
c.constraint_type = 'UNIQUE'
|
|
|
|
or c.constraint_type = 'PRIMARY KEY'
|
2018-12-19 13:41:06 +03:00
|
|
|
group by
|
2019-03-22 10:08:42 +03:00
|
|
|
c.table_schema,
|
|
|
|
c.table_name
|
2018-12-19 13:41:06 +03:00
|
|
|
) constraints on (
|
|
|
|
tables.table_schema = constraints.table_schema
|
|
|
|
AND tables.table_name = constraints.table_name
|
|
|
|
)
|
|
|
|
left outer join (
|
|
|
|
select
|
|
|
|
table_schema,
|
|
|
|
table_name,
|
|
|
|
json_build_object(
|
|
|
|
'is_updatable',
|
|
|
|
(is_updatable::boolean OR is_trigger_updatable::boolean),
|
|
|
|
'is_deletable',
|
|
|
|
(is_updatable::boolean OR is_trigger_deletable::boolean),
|
|
|
|
'is_insertable',
|
|
|
|
(is_insertable_into::boolean OR is_trigger_insertable_into::boolean)
|
|
|
|
) as view_info
|
|
|
|
from
|
|
|
|
information_schema.views v
|
|
|
|
) views on (
|
|
|
|
tables.table_schema = views.table_schema
|
|
|
|
AND tables.table_name = views.table_name
|
|
|
|
)
|
|
|
|
where
|
|
|
|
tables.table_schema = $1 AND
|
|
|
|
tables.table_name = $2
|