Elementary dependency look-up - Mailing list pgsql-hackers

From Josh Williams
Subject Elementary dependency look-up
Date
Msg-id 1252025151.8686.53.camel@lapdragon
Whole thread Raw
Responses Re: Elementary dependency look-up
List pgsql-hackers
Attached is a patch to add a couple basic dependency look-up capability
functions.  They're based off the pg_get_serial_sequence function, and
are kind of the inverse of that function in some respects.

The patch adds two new functions to the backend, pg_get_owner_object and
pg_get_owner_column.  These look up the requested object in the
pg_depend table, looking for an 'a' type dependency to another relation,
and resolve either the relation or column names to text.

postgres=# SELECT pg_get_owner_object('tbl_id_seq') AS obj,
postgres-#   pg_get_owner_column('tbl_id_seq') AS col,
postgres-#   pg_get_serial_sequence(
postgres(#     pg_get_owner_object('tbl_id_seq'),
postgres(#     pg_get_owner_column('tbl_id_seq')
postgres(#   ) AS full_circle;
    obj     | col |    full_circle
------------+-----+-------------------
 public.tbl | id  | public.tbl_id_seq
(1 row)

I tried not to be too myopic in the design, but apart from sequence
ownership I can't really think of any other uses for this.  'p'in and
'i'nternal relationships wouldn't make much sense, and 'n'ormal ones are
generally exposed in other ways.  Anyone have any input there on how
this could be expanded?

Anyway, as an immediate practical example the patch modifies psql's
describe-verbose on sequences to show the ownership information...

postgres=# \d+ tbl_id_seq
(...)
Owner: public.tbl.id

- Josh Williams


Attachment

pgsql-hackers by date:

Previous
From: "Joshua D. Drake"
Date:
Subject: Re: community decision-making & 8.5
Next
From: Itagaki Takahiro
Date:
Subject: Re: Triggers on columns