BUG #3659: should use implizit type cast in check constraint

Started by Michael Enkeover 18 years ago2 messagesbugs
Jump to latest
#1Michael Enke
michael.enke@wincor-nixdorf.com

The following bug has been logged online:

Bug reference: 3659
Logged by: Michael Enke
Email address: michael.enke@wincor-nixdorf.com
PostgreSQL version: 8.1.4
Operating system: Linux, CentOS5
Description: should use implizit type cast in check constraint
Details:

Hello,
if I have defined my own data type/operators,
in a check constraint this type is used
instead of ::text.
Shouln't be there an implizit typecast to ::text?
Otherwise I always have to add an explicit typecast
if I have conflicting types/operators
but this would not be nice.

create table b(a varchar(1) check(a in ('1','2')));
\d b:
Table "public.b"
Column | Type | Modifiers
--------+----------------------+-----------
a | character varying(1) |
Check constraints:
"b_a_check" CHECK (a = '1'::text OR a = '2'::text)

But if I have defined a type testchar and create this table again without an
explicit type cast:
\d b
Table "public.b"
Column | Type | Modifiers
--------+----------------------+-----------
a | character varying(1) |
Check constraints:
"b_a_check" CHECK (a = '1'::testchar OR a = '2'::testchar)

I can send test case files if required.

Regards,
Michael

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Michael Enke (#1)
Re: BUG #3659: should use implizit type cast in check constraint

"Michael Enke" <michael.enke@wincor-nixdorf.com> writes:

if I have defined my own data type/operators,
in a check constraint this type is used
instead of ::text.

It looks to me like you must have defined an operator =(varchar,testchar)
--- the only way a user-defined type would win over text is to have an
exact match.  This is not a good idea.  Just define =(text,testchar)
and leave it to the implicit coercion code to handle varchar.

regards, tom lane