Search Postgresql Archives

Re: column information from view

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 9/14/18 2:35 PM, Sebastian P. Luque wrote:
Hello,

I'm trying to generate a table with information on columns from a
temporary view that simply selects a subset of columns from a persistent
view in a given schema.  The persistent view joins a number of tables
with columns that may or may not have a description entered.  I need a
table with a list of columns from the temporary view, and the matching
descriptions from the underlying persistent view.

Here's my attempt at listing the temporary view's columns and respective
descriptions:

SELECT cols.ordinal_position, cols.column_name,
   col_description(cl.oid, cols.ordinal_position::INT)
FROM pg_class cl, information_schema.columns cols
WHERE cols.table_catalog='dbname' AND cols.table_schema='some_schema' AND
   cols.table_name = 'persistent_view' AND cols.table_name = cl.relname
ORDER BY cols.ordinal_position::INT;

The problem, of course, is that it lists columns from the persistent
view, instead of the subset of them in the temporary view.  Is there a
better way to do that?  Hopefully this makes sense.

create temp view c_data as select source_id, geography_desc from catfish_data ;

\d c_data
                       View "pg_temp_3.c_data"
     Column     |       Type        | Collation | Nullable | Default
----------------+-------------------+-----------+----------+---------
 source_id      | integer           |           |          |
 geography_desc | character varying |



SELECT cols.ordinal_position, cols.column_name,

col_description(cl.oid, cols.ordinal_position::INT)

FROM pg_class cl, information_schema.columns cols

WHERE cols.table_catalog='aquaculture' AND cols.table_schema ilike 'pg_temp%' AND cols.table_name = 'c_data' AND cols.table_name = cl.relname

ORDER BY cols.ordinal_position::INT;


ordinal_position | column_name | col_description

------------------+----------------+-----------------

1 | source_id | NULL

                2 | geography_desc | NULL


Thanks,
--
Seb




--
Adrian Klaver
adrian.klaver@xxxxxxxxxxx




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux