Skip to content

Commit

Permalink
return pk and fk columns
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgangwalther committed Nov 6, 2020
1 parent f4ecedb commit de6bf65
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/PostgREST/DbStructure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -686,13 +686,15 @@ allSourceColumns cols pgVer =
| otherwise = ":subselect {.*?:stmt_len 0} :location \\d+} :res(no|ult)"
sql = [qc|
with recursive
any_part_of_fk as (
pks_fks as (
-- pk + fk referencing col
select
conrelid as resorigtbl,
unnest(conkey) as resorigcol
from pg_constraint
where contype='f'
where contype IN ('p', 'f')
union
-- fk referenced col
select
confrelid,
unnest(confkey)
Expand Down Expand Up @@ -769,7 +771,7 @@ allSourceColumns cols pgVer =
join pg_attribute col on col.attrelid = tbl.oid and col.attnum = rec.resorigcol
join pg_attribute vcol on vcol.attrelid = rec.view_id and vcol.attnum = rec.view_column
join pg_namespace sch on sch.oid = tbl.relnamespace
join any_part_of_fk using (resorigtbl, resorigcol)
join pks_fks using (resorigtbl, resorigcol)
order by view_schema, view_name, view_column_name; |]

getPgVersion :: H.Session PgVersion
Expand Down

0 comments on commit de6bf65

Please sign in to comment.