postgres ERROR: target lists can have at most 1664 entries SQL state: 54000
Such column count is really huge. Without the schema/query details I cannot say, what's the reason, but I might guess there are many data columns not really required to be serialized there. Instead doing some concat magic I would suggest to merge such columns into JSON/JSONB objects which would be then easily accessible by the application. This is the classic NoSQL approach in SQL RDBMSes.