File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff 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+ ```
You can’t perform that action at this time.
0 commit comments