pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedType casting bool?
3+ messages / 3 participants
[nested] [flat]
* Type casting bool?
@ 2000-02-12 04:29 phil@Stimpy.netroedge.com
2000-02-13 00:31 ` Re: [SQL] Type casting bool? tjk@tksoft.com <tjk@tksoft.com>
0 siblings, 1 reply; 3+ messages in thread
From: phil@Stimpy.netroedge.com @ 2000-02-12 04:29 UTC (permalink / raw)
To: pgsql-sql@hub.org
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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: [SQL] Type casting bool?
2000-02-12 04:29 Type casting bool? phil@Stimpy.netroedge.com
@ 2000-02-13 00:31 ` tjk@tksoft.com <tjk@tksoft.com>
2000-02-13 06:36 ` Re: [SQL] Type casting bool? Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 3+ messages in thread
From: tjk@tksoft.com @ 2000-02-13 00:31 UTC (permalink / raw)
To: phil@Stimpy.netroedge.com; +Cc: pgsql-sql@hub.org
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
>
> ************
>
>
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: [SQL] Type casting bool?
2000-02-12 04:29 Type casting bool? phil@Stimpy.netroedge.com
2000-02-13 00:31 ` Re: [SQL] Type casting bool? tjk@tksoft.com <tjk@tksoft.com>
@ 2000-02-13 06:36 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 3+ messages in thread
From: Tom Lane @ 2000-02-13 06:36 UTC (permalink / raw)
To: tjk@tksoft.com <tjk@tksoft.com>; +Cc: phil@Stimpy.netroedge.com; pgsql-sql@hub.org
A number of people have suggested that there should be an int4(bool)
conversion function, but no one's got round to actually writing it.
Presumably the behavior ought to be
false => 0
true => 1
NULL => NULL
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2000-02-13 06:36 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-02-12 04:29 Type casting bool? phil@Stimpy.netroedge.com
2000-02-13 00:31 ` tjk@tksoft.com <tjk@tksoft.com>
2000-02-13 06:36 ` Tom Lane <tgl@sss.pgh.pa.us>
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