Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UidPs-0003zF-Ez for pgsql-bugs@arkaria.postgresql.org; Sat, 01 Jun 2013 04:27:44 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UidPr-0001dE-Vi for pgsql-bugs@arkaria.postgresql.org; Sat, 01 Jun 2013 04:27:44 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UidPr-0001d9-Ca for pgsql-bugs@postgresql.org; Sat, 01 Jun 2013 04:27:43 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UidPp-0000fI-09 for pgsql-bugs@postgresql.org; Sat, 01 Jun 2013 04:27:42 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id r514Rcu7014955; Sat, 1 Jun 2013 00:27:38 -0400 (EDT) From: Tom Lane To: Gerald Luger cc: "pgsql-bugs@postgresql.org" Subject: Re: BUG #8191: Wrong bit conversion In-reply-to: <7A3A36FE51533446AAB1EA0F6069AC8C40A5B460@HEXBOSSSERVER.hexboss.local> References: <11097.1370036031@sss.pgh.pa.us> <7A3A36FE51533446AAB1EA0F6069AC8C40A5B460@HEXBOSSSERVER.hexboss.local> Comments: In-reply-to Gerald Luger message dated "Fri, 31 May 2013 23:29:56 -0000" Date: Sat, 01 Jun 2013 00:27:38 -0400 Message-ID: <14954.1370060858@sss.pgh.pa.us> X-Pg-Spam-Score: -0.3 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Gerald Luger writes: > Shouldn't I expect all results to be 000...0001? Well, no. The SQL spec is pretty clear about the interpretation of this: b'1'::bit(64) You're taking a bit string of length 1 and casting it to bit string of length 64. That's done by appending zeroes on the right, per spec. The x'1' notation isn't in SQL99 AFAICS, but we consider that x'1' means the same as b'0001', and then the conversion from bit(4) to bit(64) is done by padding zeroes on the right. Your last case, 1::bit(64) represents casting an integer to bit(64). This operation isn't in the SQL spec either, unless I missed something. We treat this as conversion of the integer's twos-complement representation to a bit string, presuming big-endian representation of the integer. Now you can quibble with various of the details above, but in the end they are all arbitrary decisions. We've made them that way, and it would take a pretty impressive argument to persuade us to break existing applications by changing them. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs