From: tjk@tksoft.com <tjk@tksoft.com>
To: phil@Stimpy.netroedge.com
Cc: pgsql-sql@hub.org
Subject: Re: [SQL] Type casting bool?
Date: Sat, 12 Feb 2000 16:31:25 -0800 (PST)
Message-ID: <200002130031.QAA16446@uno.tksoft.com> (raw)
In-Reply-To: <20000211202906.E19246@Stimpy.netroedge.com>
If you are using Postgres 6.5 +, you can use
select case when mybool then 1 else 0 end from mytable;
Of course, this would not, explicitly, take into consideration
null fields.
Troy
>
>
> This seems like it would be simple, but I'm having troubles getting it
> to work. All I wish to do is have Postgresql return '0' or '1'
> instead of 'f' or 't' for bool types. This would simplify life for me
> since I'm trying to dump these values right into expressions outside
> of the context of SQL. Right now my parsers are choking on the 't's
> and 'f's from PostgreSQL.
>
> I've tried:
>
> select mybool::int4;
>
> But, I get,
>
> ERROR: function int4(bool) does not exist
>
> Hummm.... I want to do something like:
>
> select (mybool?1:0);
>
> But, that's not the right syntax. I'd love to be able to get this
> working w/o defining new functions or types (i.e., make it portable).
>
> Ideas? I've poured over the documentation and the current function
> and operators, but this doesn't seem to be implemented?!
>
> Thanks!
>
>
> Phil
>
> --
> Philip Edelbrock -- IS Manager -- Edge Design, Corvallis, OR
> phil@netroedge.com -- http://www.netroedge.com/~phil
> PGP F16: 01 D2 FD 01 B5 46 F4 F0 3A 8B 9D 7E 14 7F FB 7A
>
> ************
>
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: tjk@tksoft.com, phil@Stimpy.netroedge.com, pgsql-sql@hub.org
Subject: Re: [SQL] Type casting bool?
In-Reply-To: <200002130031.QAA16446@uno.tksoft.com>
References: <20000211202906.E19246@Stimpy.netroedge.com> <200002130031.QAA16446@uno.tksoft.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox