pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Gerald Luger <GeraldLuger@hexboss.com>
Cc: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: Re: BUG #8191: Wrong bit conversion
Date: Sat, 01 Jun 2013 00:27:38 -0400
Message-ID: <14954.1370060858@sss.pgh.pa.us> (raw)
In-Reply-To: <7A3A36FE51533446AAB1EA0F6069AC8C40A5B460@HEXBOSSSERVER.hexboss.local>
References: <E1Ui5wN-0007sy-5H@wrigleys.postgresql.org>
	<11097.1370036031@sss.pgh.pa.us>
	<7A3A36FE51533446AAB1EA0F6069AC8C40A5B460@HEXBOSSSERVER.hexboss.local>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Gerald Luger <GeraldLuger@hexboss.com> 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



view thread (8+ messages)

Message-ID: <14954.1370060858@sss.pgh.pa.us>
Permalink:  ../14954.1370060858@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/14954.1370060858@sss.pgh.pa.us

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, GeraldLuger@hexboss.com
  Subject: Re: BUG #8191: Wrong bit conversion
  In-Reply-To: <14954.1370060858@sss.pgh.pa.us>
  References: <E1Ui5wN-0007sy-5H@wrigleys.postgresql.org> <11097.1370036031@sss.pgh.pa.us> <7A3A36FE51533446AAB1EA0F6069AC8C40A5B460@HEXBOSSSERVER.hexboss.local> <14954.1370060858@sss.pgh.pa.us>

* 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