pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: marc@intershop.de
To: pgsql-bugs@postgresql.org
Subject: BUG #8153: check constraint results in a lot of casts
Date: Mon, 13 May 2013 13:30:24 +0000
Message-ID: <E1Ubspc-0005ly-3s@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

The following bug has been logged on the website:

Bug reference:      8153
Logged by:          Marc Mamin
Email address:      marc@intershop.de
PostgreSQL version: 9.2.4
Operating system:   Linux &amp; windows
Description:        

hello,

This is not a functional bugs, but it appers (at least for me...) that
following constraint gets defined with some unecessary overweight:

create table test (a varchar);

(1) alter table test add constraint test_ck check ( a in ('a','b'));

I'd expect this to be resolved in CHECK (a = ANY (ARRAY['a'::character
varying, 'b'::character varying]) ).
I've tried further variantes. (3) looks better but there is always a cast on
the table side.

(2) alter table test add constraint test_ck_2 check ( a = ANY
(ARRAY['a'::character varying, 'b'::character varying] ));    
(3) alter table test add constraint test_ck_3 check ( a = ANY
(ARRAY['a'::text, 'b'] ));    


\d+ test
                              Table "public.test"
 Column |       Type        | Modifiers | Storage  | Stats target |
Description
--------+-------------------+-----------+----------+--------------+-------------
 a      | character varying |           | extended |              |
Check constraints:
    "test_ck"   CHECK (a::text = ANY (ARRAY['a'::character varying,
'b'::character varying]::text[]))
    "test_ck_2" CHECK (a::text = ANY (ARRAY['a'::character varying,
'b'::character varying]::text[]))
    "test_ck_3" CHECK (a::text = ANY (ARRAY['a'::text, 'b'::text]))

best regards,

Marc Mamin



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



Message-ID: <E1Ubspc-0005ly-3s@wrigleys.postgresql.org>
Permalink:  ../E1Ubspc-0005ly-3s@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/E1Ubspc-0005ly-3s@wrigleys.postgresql.org

 · 

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: marc@intershop.de
  Subject: Re: BUG #8153: check constraint results in a lot of casts
  In-Reply-To: <E1Ubspc-0005ly-3s@wrigleys.postgresql.org>
  References: <E1Ubspc-0005ly-3s@wrigleys.postgresql.org>

* 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