From: Eric Veldhuyzen <ericv@xs4all.net>
To: Achilleus Mantzios <achill@matrix.gatewaynet.com>
Cc: Eric Veldhuyzen <ericv@xs4all.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: cast of integer to bool doesn't work (anymore?)
Date: Fri, 21 Mar 2003 15:19:40 +0100
Message-ID: <20030321141940.GD6540@opium.xs4all.nl> (raw)
In-Reply-To: <Pine.LNX.4.44.0303211553560.2751-100000@matrix.gatewaynet.com>
References: <20030321133646.GC6540@opium.xs4all.nl>
<Pine.LNX.4.44.0303211553560.2751-100000@matrix.gatewaynet.com>
On Fri, Mar 21, 2003 at 03:54:56PM -0200, Achilleus Mantzios wrote:
> On Fri, 21 Mar 2003, Eric Veldhuyzen wrote:
>
> > Hi,
> >
> > Here at my work we use on the production servers PostgreSQL version
> > 7.2.3, but I have version 7.3.2 (from the Debian distribution) on my
> > workstation. Now I noticed yesterday that the query 'select 0::boolean;'
> > works on the production server, it gives the output:
> >
> > # select 0::boolean;
> > bool
> > ------
> > f
> > (1 row)
> >
> > Perfect. But when I try this on my local version of postgreSQL I get
> > this:
> >
> > # select 0::boolean;
> > ERROR: Cannot cast type integer to boolean
>
> Just wrap 0 with single quotes,
> e.g.
> # select '0'::boolean;
Yeah, I tried that, and yes, that does work from the psql prompt. This
basically means that I fool psql into thinking that it is a string, and
then forcing it to cast to a boolean, right? But my problem is that it
does not work when I use that in the prepare statement from perl. For
example:
my $sth = $dbh->prepare(
"INSERT INTO object_def (name, meant_as_subobject) VALUES (?,?::bool)");
$sth->execute('test', 0);
This code gives me the error
"DBD::Pg::st execute failed: ERROR: Cannot cast type integer to boolean"
on 7.3, but it works on 7.2 and below. If I change the prepare to
my $sth = $dbh->prepare(
"INSERT INTO object_def (name, meant_as_subobject) VALUES (?,'?'::bool)");
I will get the error
"execute called with 2 bind variables, 1 needed" because the
perl database driver can't handle the quote characters in a prepare statement.
This here is ofcourse a simplyfied example, in our real project the
prepare statement is dynamically build by a library that knows the
database schema, and tries to do conversions while builing
the prepared statement. One if them is checking the columntypes, and
replace the ? with ?::bool in the prepared statement if the columntype
is of boolean type. Another is something similar if the columntype is a
timestamp or date (I haven't tested if that part still works though, I
realize now).
--
Eric Veldhuyzen
xs4all NSA team
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: ericv@xs4all.net, achill@matrix.gatewaynet.com
Subject: Re: cast of integer to bool doesn't work (anymore?)
In-Reply-To: <20030321141940.GD6540@opium.xs4all.nl>
* 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