Skip to content

Commit 9d225d1

Browse files
authored
Update TODO.md
1 parent ed303d8 commit 9d225d1

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

TODO.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,3 +450,32 @@ where created_at < now() - interval '1 year'
450450
or session_id is not null
451451
or is_auto_generated is not null);
452452
```
453+
454+
455+
# primary_key_columns
456+
457+
source https://supabase.com/blog/audit
458+
459+
```sql
460+
create or replace function audit.primary_key_columns(entity_oid oid)
461+
returns text[]
462+
stable
463+
security definer
464+
language sql
465+
as $$
466+
-- Looks up the names of a table's primary key columns
467+
select
468+
coalesce(
469+
array_agg(pa.attname::text order by pa.attnum),
470+
array[]::text[]
471+
) column_names
472+
from
473+
pg_index pi
474+
join pg_attribute pa
475+
on pi.indrelid = pa.attrelid
476+
and pa.attnum = any(pi.indkey)
477+
where
478+
indrelid = $1
479+
and indisprimary
480+
$$;
481+
```

0 commit comments

Comments
 (0)