Thread: How to get comments for view columns?

How to get comments for view columns?

From
eugene.mindrov@gmail.com
Date:
Hi,
is there any way to get comment meta-information for columns in a
view? I mean, suppose I have several tables and some of their columns
have comments, then I define a view on these tables, and what I want
is to somehow retrieve comments (if any) for those columns which are
selected in a view.
I tried to play with system catalog tables trying to dig out the
necessary info, but to no avail.
The best I could do is to retrieve all "dependent" columns (which
belong to underlying tables) for a view with their comments, but I
couldn't find any way to determine a relation between "dependent"
columns and those actually selected in a view.
So, is this an impossible task and should I invent my own meta-
dictionary or I'm missing something important?


Re: How to get comments for view columns?

From
Tom Lane
Date:
eugene.mindrov@gmail.com writes:
> is there any way to get comment meta-information for columns in a
> view? I mean, suppose I have several tables and some of their columns
> have comments, then I define a view on these tables, and what I want
> is to somehow retrieve comments (if any) for those columns which are
> selected in a view.
> I tried to play with system catalog tables trying to dig out the
> necessary info, but to no avail.
> The best I could do is to retrieve all "dependent" columns (which
> belong to underlying tables) for a view with their comments, but I
> couldn't find any way to determine a relation between "dependent"
> columns and those actually selected in a view.

What do you consider "selected"?  Given a view defined as

    select a, b, c+d as sum from tab where e > 42;

what output are you wishing for?

AFAIR the dependency mechanism will treat a,b,c,d,e alike.  To do more
you'd need to grovel through the pg_rewrite expression for the view's
select rule, which'd be excruciatingly painful from a client program
for lack of any supporting code.

            regards, tom lane

Re: How to get comments for view columns?

From
eugene.mindrov@gmail.com
Date:
Tom Lane wrote:
> What do you consider "selected"?  Given a view defined as
>
>     select a, b, c+d as sum from tab where e > 42;
>
> what output are you wishing for?
>
> AFAIR the dependency mechanism will treat a,b,c,d,e alike.  To do more
> you'd need to grovel through the pg_rewrite expression for the view's
> select rule, which'd be excruciatingly painful from a client program
> for lack of any supporting code.
>
>             regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
>                http://archives.postgresql.org/

Sorry for not being overly accurate, I didn't consider a view with
expressions as columns, they slipped my mind, because the views I was
interested in contain only table columns, no expressions whatsoever.
But seems you're right, there's no easy way to extract underlying
comments...