pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@gmail.com>
To: pgsql-sql@postgresql.org
Cc: zoulx1982 <zoulx1982@163.com>
Subject: Re: type cast about int to bit
Date: Mon, 6 Feb 2012 17:19:11 -0800
Message-ID: <201202061719.12213.adrian.klaver@gmail.com> (raw)
In-Reply-To: <18656bf8.13415.13551499b55.Coremail.zoulx1982@163.com>
References: <18656bf8.13415.13551499b55.Coremail.zoulx1982@163.com>

On Sunday, February 05, 2012 10:11:12 pm zoulx1982 wrote:
> hi,
> there is a problem about type cast that i don't understand, follow is my
> test.
> 
> postgres=# select 10::bit(3);
>  bit
> -----
>  010
> (1 row)
> postgres=# select 10::bit varying(3);
> ERROR:  cannot cast type integer to bit varying
> LINE 1: select 10::bit varying(3);
>                  ^
> postgres=#
> 
> my question is why int can cast to bit , i want to know the reason.
> thank you for your timing.

My guess it depends on the  fact that bit types are stored as either char or 
varchar depending on whether they are bit or bit varying.
In the first case you are basically doing an int-->char, for which there is a 
built in cast.
In the second case you are doing int-->varchar for which there is not a cast.


-- 
Adrian Klaver
adrian.klaver@gmail.com



view thread (4+ messages)  latest in thread

Message-ID: <201202061719.12213.adrian.klaver@gmail.com>
Permalink:  ../201202061719.12213.adrian.klaver@gmail.com/
Also on:    postgresql.org/message-id/201202061719.12213.adrian.klaver@gmail.com

 · 

reply

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: adrian.klaver@gmail.com, zoulx1982@163.com
  Subject: Re: type cast about int to bit
  In-Reply-To: <201202061719.12213.adrian.klaver@gmail.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