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
질문됨 일 년 전215회 조회
1개 답변
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
전문가
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠