Search code examples
firebirdfirebird-3.0

How to disable "heading" for all firebird subrequests


I have a request for firebird with concatenation and using nested select and list (), and then written this to the file. The first command is SET HEADING OFF;

SET HEADING OFF;
SELECT DISTINCT '"' || REPLACE(TRIM(COALESCE(x.column, '')), '"', '""')
|| '"; "' || REPLACE(TRIM(COALESCE(x.column2, '')), '"', '""')
|| '"; "' || REPLACE(TRIM(COALESCE(list(DISTINCT x.column3, ','), '')), '"', '""')
|| '";'
FROM (
     SELECT ycolumn AS column, ycolumn1 AS column1, ycolumn2 AS column2, list(DISTINCT ycolumn3, ',') AS column3
FROM (
     SELECT d.column AS ycolumn, c.column1 AS ycolumn1, dc.column2 AS ycolumn2, ws.column3 AS ycolumn3
     FROM ...
     )y
     GROUP BY ycolumn, ycolumn1, ycolumn2
) x
GROUP BY x.column, x.column1, x.column3
;

The problem is that the headers for the nested SELECTs are not disabled and outputs file is like this:

==============================================================================
            0:218
==============================================================================
CONCATENATION:
"field"; "field1"; "field2"; "field3";

Is it possible to disable headers for all requests?


Solution

  • The problem is that LIST produces a BLOB SUB_TYPE TEXT, and ISQL defaults to using configuration BLOBDISPLAY set to 1 (to show BLOB SUB_TYPE TEXT). With this setting, ISQL will automatically output all text blobs inline per row, but to discern which blob is which, it will include the column alias when showing the blob content.

    You could turn off blobdisplay using SET BLOBDISPLAY OFF, but then your query result will only show the blob-id and not the blob content which is probably not what you want. For the query in your question it would only show:

                0:218
    

    The alternative is to cast the query to a VARCHAR of sufficient size:

    SELECT DISTINCT cast('"' || REPLACE(TRIM(COALESCE(x.column, '')), '"', '""')
    || '"; "' || REPLACE(TRIM(COALESCE(x.column2, '')), '"', '""')
    || '"; "' || REPLACE(TRIM(COALESCE(list(DISTINCT x.column3, ','), '')), '"', '""')
    || '";' as varchar(8191))
    FROM ...
    

    Max VARCHAR size is 8191 for character set UTF8, or 32765 for a single byte character set, but there are additional constraints to row length (maximum 64KB total).