postgresql - redshift - how to use listagg with information_schema.columns table -


i'm using redshift , create comma separated list of columns. i'm trying grab column names information schema using listagg:

select   listagg(column_name,',') within group (order ordinal_position)     information_schema.columns   table_schema = 'my_schema' ,     table_name = 'my table'; 

i'm getting following error:

[amazon](500310) invalid operation: function (listagg(text,text)) must applied on @ least 1 user created tables; 

although not answer how apply listagg on information_schema, can recommend alternative method of using listagg on pg catalog tables instead.

try this:

select distinct listagg(attname, ',') within group (order a.attsortkeyord) "columns" pg_attribute a, pg_namespace ns, pg_class c, pg_type t, stv_tbl_perm p, pg_database db t.oid=a.atttypid , a.attrelid=p.id , ns.oid = c.relnamespace , db.oid = p.db_id , c.oid = a.attrelid , typname not in ('oid','xid','tid','cid') , ns.nspname = 'my_schema' , rtrim(name) = 'my table' 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -