How do I avoid writing SQL that depends on settings?
0
votes
1
answer
53
views
[PostgreSQL docs note](https://www.postgresql.org/docs/17/datatype-binary.html) :
> The bytea type supports two formats for input and output: “hex” format and PostgreSQL's historical “escape” format. Both of these are always accepted on input. The output format depends on the configuration parameter bytea_output; the default is hex.
I always interpreted it as being specific to only the displaying of output, but I see now that you can get differing query results based on the setting.
For example, on PostgreSQL:
=> set bytea_output to 'hex';
SET
=> select length('\x2020'::bytea::text);
length
--------
6
(1 row)
=> set bytea_output to 'escape';
SET
=> select length('\x2020'::bytea::text);
length
--------
2
(1 row)
To make my application more robust, I want the SQL I write to be independent of toggles like this. How can I achieve this?
Asked by Janus Troelsen
(139 rep)
May 8, 2025, 07:16 PM
Last activity: May 9, 2025, 04:24 AM
Last activity: May 9, 2025, 04:24 AM