how to achieve LISTagg functionality

0

Redshift gives me the error select table_schema,table_name,LISTAGG(column_name,', ') within group (order by ordinal_position asc) from information_schema.columns
where table_name = 'abcde' and table_schema = 'xyz' group by 1,2

i tried to create mytable insert into mytable select table_schema , table_name , ordinal_position as colpos, column_name as ColumnName from information_schema.columns
where table_name = 'abcde' and table_schema = 'xyz' group by 1,2

gives me error: Function "has_column_privilege(oid,smallint,text)" not supported. Function "has_column_privilege(oid,smallint,text)" not supported. Function "has_table_privilege(oid,text)" not supported. Function "has_table_privilege(oid,text)" not supported. Function "has_table_privilege(oid,text)" not supported.

i would want to acheive this which would will be later used in my stored proc.

table_schema , tablename, distkey, sortkey, columns xyz abcde col1 col2,col3 col1,col2,col3,col4,col5,col6,col7

i also tried with select schema_name as databasename,table_name as tablename,ordinal_position as colpos,column_name from pg_catalog.svv_all_columns where database_name='prod123' and schema_name='xyz' and table_name='abcde' order by 1,2,3,4

get the error: Function "has_column_privilege(oid,smallint,text)" not supported. Function "has_column_privilege(oid,smallint,text)" not supported. Failed to get redshift columns from *******

thanks KN

KN
asked a year ago210 views
1 Answer
2

LISTAGG is a "User table only function" which means you cannot apply this function on the catalog tables.

You should get the below error if you apply LISTAGG function to information_schema tables:

One or more of the used functions must be applied on at least one user created tables. Examples of user table only functions are LISTAGG, MEDIAN, PERCENTILE_CONT, etc

profile pictureAWS
EXPERT
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions