pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: Susan Hurst <susan.hurst@brookhurstdata.com>
Cc: Discuss List Postgres <pgsql-general@lists.postgresql.org>
Subject: Re: Displaying Comments in Views
Date: Mon, 28 Jan 2019 15:41:56 +0000
Message-ID: <87lg34izi5.fsf@news-spur.riddles.org.uk> (raw)
In-Reply-To: <8d48b89ca871afcce64a6b78d2db2b0c@mail.brookhurstdata.net>
References: <8d48b89ca871afcce64a6b78d2db2b0c@mail.brookhurstdata.net>

>>>>> "Susan" == Susan Hurst <susan.hurst@brookhurstdata.com> writes:

 Susan> What is the trick for displaying column comments in views? The
 Susan> query below works as expected when the table_schema includes
 Susan> tables, however it shows nothing when the table_schema contains
 Susan> only views. I tried putting the query into an inline statement
 Susan> as a column selection in a wrapper query...I got all the
 Susan> table/column data but the comment column values were all null.

 Susan>   from pg_catalog.pg_statio_all_tables  st

That is the wrong place to look for the purposes of this query, since as
the name implies it only shows tables (and not views, since
non-materialized views don't have or need I/O statistics). Also, it's
_NOT_ the place to look when you just want a list of tables in the db or
to look up tables by oid; use pg_class for that.

I'd have gone with something along the lines of:

select n.nspname as table_schema,
       c.relname as table_name,
       a.attname as column_name,
       pd.description as description
  from pg_class c
       join pg_namespace n on (n.oid=c.relnamespace)
       join pg_attribute a on (a.attrelid=c.oid
                               and a.attnum > 0
                               and not a.attisdropped)
       join pg_description pd
         on (pd.classoid='pg_class'::regclass
             and pd.objoid=c.oid
             and pd.objsubid=a.attnum)
 where n.nspname = 'devops'
 order by n.nspname, c.relname, a.attname;

-- 
Andrew (irc:RhodiumToad)




view thread (5+ messages)  latest in thread

Message-ID: <87lg34izi5.fsf@news-spur.riddles.org.uk>
Permalink:  ../87lg34izi5.fsf@news-spur.riddles.org.uk/
Also on:    postgresql.org/message-id/87lg34izi5.fsf@news-spur.riddles.org.uk

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: andrew@tao11.riddles.org.uk, susan.hurst@brookhurstdata.com
  Subject: Re: Displaying Comments in Views
  In-Reply-To: <87lg34izi5.fsf@news-spur.riddles.org.uk>
  References: <8d48b89ca871afcce64a6b78d2db2b0c@mail.brookhurstdata.net> <87lg34izi5.fsf@news-spur.riddles.org.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox