Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id A5FE974733B for ; Mon, 6 Feb 2012 21:19:31 -0400 (AST) Received: from mail-iy0-f174.google.com ([209.85.210.174]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RuZiU-0001Fz-Sf for pgsql-sql@postgresql.org; Tue, 07 Feb 2012 01:19:31 +0000 Received: by iacb35 with SMTP id b35so9292428iac.19 for ; Mon, 06 Feb 2012 17:19:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:subject:date:user-agent:cc:references:in-reply-to :mime-version:content-type:content-transfer-encoding:message-id; bh=l2leOPI1AfWfx8+f32FRJjMn7HLC950qkZqJ4Cf8zow=; b=j54g3mU9Fp/GSNqMwVP+KBrbVebrrZJlupTqb483mhGjJ4zURINlWr+1mV5ywZpofL rjwtHL2IKZl3CQeMpVQ21hdN+IU2jDEGCXUHqnRa+py9mm1P/NlWVJfmqLN0SZdFhUvs vUcNfOFWkyofN/R9M5/BjWL7arWrp4dgcbjiw= Received: by 10.50.89.196 with SMTP id bq4mr23823689igb.26.1328577557666; Mon, 06 Feb 2012 17:19:17 -0800 (PST) Received: from tucker.localnet (c-24-17-164-54.hsd1.wa.comcast.net. [24.17.164.54]) by mx.google.com with ESMTPS id x18sm29955420ibi.2.2012.02.06.17.19.14 (version=SSLv3 cipher=OTHER); Mon, 06 Feb 2012 17:19:16 -0800 (PST) From: Adrian Klaver To: pgsql-sql@postgresql.org Subject: Re: type cast about int to bit Date: Mon, 6 Feb 2012 17:19:11 -0800 User-Agent: KMail/1.13.5 (Linux/2.6.32-38-generic; KDE/4.4.5; i686; ; ) Cc: zoulx1982 References: <18656bf8.13415.13551499b55.Coremail.zoulx1982@163.com> In-Reply-To: <18656bf8.13415.13551499b55.Coremail.zoulx1982@163.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <201202061719.12213.adrian.klaver@gmail.com> X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201202/19 X-Sequence-Number: 36312 On Sunday, February 05, 2012 10:11:12 pm zoulx1982 wrote: > hi=EF=BC=8C > there is a problem about type cast that i don't understand, follow is my > test. >=20 > postgres=3D# select 10::bit(3); > bit > ----- > 010 > (1 row) > postgres=3D# select 10::bit varying(3); > ERROR: cannot cast type integer to bit varying > LINE 1: select 10::bit varying(3); > ^ > postgres=3D# >=20 > 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 o= r=20 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=20 built in cast. In the second case you are doing int-->varchar for which there is not a cas= t. =2D-=20 Adrian Klaver adrian.klaver@gmail.com