How to deal with SQL validation error -5940 (Excessively complex expression)?


How to deal with SQL validation error -5940 (Excessively complex expression)?


I'm composing a query to concatenate all columns into a string from a very wide table. My SQL looks like

SELECT T0.C0 || '-' || T0.C1 || '-' || ... T0.CN AS CONCATENATED_STR FROM (SELECT T0.C0, T0.C1, ..., T0.CN FROM WIDE_TABLE T0) T0

However the database complains this SQL statement during validation. The error message is:

"HY000-5940 [ODBC Teradata Driver] Excessively complex expression."

According to Teradata's document this error happened within RES modules during expression resolution, and it is adviced to "correct the condition and resubmit". However this seems doesn't fit to my situation so I have no idea how to improve the statement.

If I try to shorten the statement by concatenating only part of the columns, sometimes I got error:

"HY001-3710 [ODBC Teradata Driver] Insufficient memory to parse this request, during Optimizer phase."

My question are:

(1) How can I rewrite the SQL statement such that Teradata is happen to parse and execute?

(2) What is the limit for concatenating string in SQL? What is the limit for submiting such query to the database? Is it configurable or depends on hardware configuration?

Many thanks!