Skip site navigation (1) Skip section navigation (2)

Re: [BUGS] Mapping Hibernate boolean to smallint(Postgresql)

From: Mark Kirkwood <mark(dot)kirkwood(at)catalyst(dot)net(dot)nz>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: [BUGS] Mapping Hibernate boolean to smallint(Postgresql)
Date: 2010-09-30 22:09:33
Message-ID: 4CA50A9D.2030707@catalyst.net.nz (view raw or flat)
Thread:
Lists: pgsql-bugspgsql-jdbc
On 01/10/10 10:50, stagirus wrote:
> Oliver: Thank you for your generous response. The options you suggested were
> not yet viable. Disagreeing is part of human nature. No worries there.
>
> But if you review Craig's remarks carefully, this issue is likely outside
> the scope of JDBC drivers. It is more to do with the Postgresql DB Engine
> that is not happy to cast or convert boolean values to SMALLINT columns.
>
> Craig.. is my interpretation of your comments right?
>
>    

This could be an interesting related factor (using 9.0 here):

test=# create table smallinttest(val smallint);
CREATE TABLE

test=# create table booltest(val bool);
CREATE TABLE

test=# insert into booltest values (1);
ERROR:  column "val" is of type boolean but expression is of type integer
LINE 1: insert into booltest values (1);

test=# insert into booltest values ((1::smallint)::bool);
ERROR:  cannot cast type smallint to boolean
LINE 1: insert into booltest values ((1::smallint)::bool);
                                                   ^
                                   ^
HINT:  You will need to rewrite or cast the expression.
test=# insert into booltest values (1::bool);
INSERT 0 1

test=# insert into smallinttest values (true);
ERROR:  column "val" is of type smallint but expression is of type boolean
LINE 1: insert into smallinttest values (true);
                                          ^
HINT:  You will need to rewrite or cast the expression.
test=# insert into smallinttest values (true::smallint);
ERROR:  cannot cast type boolean to smallint
LINE 1: insert into smallinttest values (true::smallint);
                                              ^
test=# insert into smallinttest values (true::int);
INSERT 0 1


So looks like we are missing type casts BOOLEAN <-> SMALLINT, given that 
we can happily cast to and from INTEGER.

Before getting too excited, note that the server is clearly not doing 
automated casts under any circumstances, I had to coerce it - so might 
not help you even if we added such casts.

Cheers

Mark

In response to

pgsql-bugs by date

Next:From: Robert HaasDate: 2010-09-30 22:11:58
Subject: Re: Unexpected omission of tables with duplicate names across schemas
Previous:From: Oliver JowettDate: 2010-09-30 22:08:47
Subject: Re: [BUGS] Mapping Hibernate boolean to smallint(Postgresql)

pgsql-jdbc by date

Next:From: stagirusDate: 2010-09-30 22:18:53
Subject: Re: [BUGS] Mapping Hibernate boolean to smallint(Postgresql)
Previous:From: Oliver JowettDate: 2010-09-30 22:08:47
Subject: Re: [BUGS] Mapping Hibernate boolean to smallint(Postgresql)

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group