Thread: Column Headings using Comment?

Column Headings using Comment?

From
tully
Date:
Is there an option for psql to use the entry in Comments for "pretty"
column headings in a report?  For example, instead of printing the
column name of "last" in the heading, the option would print "Last
Name" that is contained in the Comments field.

The only two alternatives I've found so far is to use "SELECT AS" or
to mangle the "\d+" output from psql with awk, which are both
cumbersome solutions, especially when a "select *" is possible.

Can anyone help?

--tully

Re: Column Headings using Comment?

From
Bruce Momjian
Date:
tully wrote:
> Is there an option for psql to use the entry in Comments for "pretty"
> column headings in a report?  For example, instead of printing the
> column name of "last" in the heading, the option would print "Last
> Name" that is contained in the Comments field.
>
> The only two alternatives I've found so far is to use "SELECT AS" or
> to mangle the "\d+" output from psql with awk, which are both
> cumbersome solutions, especially when a "select *" is possible.
>
> Can anyone help?

Ideally, you could do something like:

    SELECT 1 AS (SELECT description FROM pg_description WHERE ...);

but we don't support subqueries in AS clauses.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

system tables

From
"M. Bastin"
Date:
Hi,

I've spent several hours browsing the system tables and the online
documentation about them but I still can't find how to extract
following information:

1. How do I find the user name for a given pid?

2. Where's the list that links all valid text encoding names with the
numbers representing them?  (E.g. UNICODE = 6)

Is there an easy way to recoup how the different system tables are
related to each other, or does one simply have to know?

Thanks,

Marc

Re: system tables

From
Tom Lane
Date:
"M. Bastin" <marcbastin@mindspring.com> writes:
> 1. How do I find the user name for a given pid?

See pg_stat_activity.

> 2. Where's the list that links all valid text encoding names with the
> numbers representing them?  (E.g. UNICODE = 6)

I don't believe this list exists as a system catalog.  It is accessible
through the pg_char_to_encoding() and pg_encoding_to_char() functions,
though.

> Is there an easy way to recoup how the different system tables are
> related to each other, or does one simply have to know?

See the docs:
http://www.postgresql.org/docs/7.4/static/catalogs.html

            regards, tom lane

Re: Column Headings using Comment?

From
tully
Date:
On Tue, 2 Mar 2004 14:00:29 -0500 (EST), pgman@candle.pha.pa.us (Bruce
Momjian) wrote:

>Ideally, you could do something like:
>
>    SELECT 1 AS (SELECT description FROM pg_description WHERE ...);
>
>but we don't support subqueries in AS clauses.

That would be much nicer.  I'm afraid I got spoiled by a simple little
relational database called Unity, that I used years ago at AT&T.  Just
a letter parameter added would use the "pretty" heading instead of the
field name, so one setup handled all subsequent queries.  It would be
so nice if psql did something like that and everything is there to do
it except the support for the argument.

I really like how postgresql behaves, especially how psql lets me
create complicated web page results with small shell and awk scripts.
Transactions are a life-saver and couldn't be easier to code.  I think
I'm hooked.  Now if I could only talk a postgres developer into coding
that "pretty" option into psql...  ;)

Thanks Bruce.

--tully