LISTAGG on svv_redshift_columns - Gives error because it can only be run on compute nodes - Looking for a workaround

1

I am trying to perform a LISTAGG on svv_redshift_columns (below query), however I receive the error ERROR: 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.

From a StackOverflow post, I learned that it is probably because LISTAGG can only be used on compute nodes, and svv_redshift_columns is on the leader node.

With that said, what would be the best workaround? I am thinking a stored procedure may be the best option to return the results that I need.

Query

select
    schema_name,
    table_name,
    listagg(column_name, ', ') within group (order by ordinal_position) as columns_combined
from svv_redshift_columns
group by schema_name, table_name;
질문됨 2년 전1577회 조회
2개 답변
1

no, you cannot create a user table based on svv_redshift_columns due to infamous "Specified types or functions (one per INFO message) not supported on Redshift tables" error. However, it works for svv_columns view. I am not sure what is the difference between these views except column names.

답변함 일 년 전
0

If this is a one-time thing then you can create a user table with the data. Once you have such table you should be able to execute the listagg function.

profile pictureAWS
답변함 2년 전

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

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

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