Cast all boolean fields in a SELECT * query to integer
4
votes
1
answer
5055
views
In PostgreSQL, I can cast individual boolean fields to integer when I want to get 0/1 output instead of f/t.
SELECT some, thing, mybool::integer FROM mytable;
But is there a way to ask PostgreSQL to do it for any boolean field in the query, without specifying the field name?
If I have:
SELECT * FROM mytable;
I would like any bools to be output as 0/1.
In this particular case, I'm using
psql
. Didn't see anything in it's options or pset
settings, so I hoped there might be some global config in the database, or some obscure SQL syntax which might do it.
Asked by mivk
(565 rep)
Feb 28, 2017, 03:15 PM
Last activity: Jun 9, 2021, 02:13 PM
Last activity: Jun 9, 2021, 02:13 PM