Re: type cast about int to bit

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: zoulx1982 <zoulx1982(at)163(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: type cast about int to bit
Date: 2012-02-07 03:28:55
Message-ID: 201202061928.56405.adrian.klaver@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Monday, February 06, 2012 6:42:45 pm zoulx1982 wrote:
> you mean there is no cast function for int to varchar ?
> i see sure it is.
>
That is why I said my guess:) If you want to see what is actually going on take
a look at:
http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/backend/utils/adt/varbit.c;h=adb08369ed28ab6b52aa2cd5213bcd5b4d8de7ad;hb=HEAD

The ERROR though is coming further up, in the parser , if I am following
correctly. This because as you have found out there is no direct cast from
integer to varbit. Why that is for someone else to answer, as I don't know.

Though a little playing around got this, not pretty but it seems to work:

test(5432)aklaver=>SELECT 10::bit(3)::varbit(3);
varbit
--------
010
(1 row)

test(5432)aklaver=>SELECT 10::bit(3)::varbit(4);
varbit
--------
010
(1 row)

test(5432)aklaver=>SELECT 10::bit(4)::varbit(4);
varbit
--------
1010
(1 row)

test(5432)aklaver=>SELECT 10::bit(4)::varbit(3);
varbit
--------
101

--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bear 2012-02-07 14:00:50 problem with nested dblink function
Previous Message Adrian Klaver 2012-02-07 01:19:11 Re: type cast about int to bit