dbTalk Databases Forums  

[BUGS] domain on bit(N) type produces strange results

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] domain on bit(N) type produces strange results in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Kris Jurka
 
Posts: n/a

Default [BUGS] domain on bit(N) type produces strange results - 11-05-2004 , 11:37 PM







Creating a domain on bit(N) doesn't seem to work as expected when casting
to the domain type.

CREATE DOMAIN bit4 AS bit(4);

SELECT 7::bit(4), 7::bit4;
bit | bit4
------+------
0111 | 1000
(1 row)


Reported in #postgresql by msw_alt.

Kris Jurka

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org

Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] domain on bit(N) type produces strange results - 11-06-2004 , 12:43 AM






Kris Jurka <books (AT) ejurka (DOT) com> writes:
Quote:
Creating a domain on bit(N) doesn't seem to work as expected when casting
to the domain type.

CREATE DOMAIN bit4 AS bit(4);

SELECT 7::bit(4), 7::bit4;
bit | bit4
------+------
0111 | 1000
(1 row)
What's going on here is that "7::bit4" is implemented as
"7::bit::bit(4)", and since 7::bit is taken to mean 7::bit(1),
the result follows.

Bit is the only typmod-using datatype for which casting to the type
with typmod -1 risks discarding information. In a brief look I'm
not sure whether this can easily be fixed without introducing unwanted
side-effects.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly


Reply With Quote
  #3  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] domain on bit(N) type produces strange results - 11-06-2004 , 12:03 PM



I wrote:
Quote:
Kris Jurka <books (AT) ejurka (DOT) com> writes:
Creating a domain on bit(N) doesn't seem to work as expected when casting
to the domain type.

What's going on here is that "7::bit4" is implemented as
"7::bit::bit(4)", and since 7::bit is taken to mean 7::bit(1),
the result follows.
I've fixed it to collapse this into a direct "7::bit(4)" coercion.
Thanks for the test case.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.