Array string casts with SELECT but not SELECT DISTINCT

From: Ken Tanzer <ken(dot)tanzer(at)gmail(dot)com>
To: PG-General Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Array string casts with SELECT but not SELECT DISTINCT
Date: 2015-02-20 04:18:39
Message-ID: CAD3a31UCtwAZPKS7UjSjXWxHdWnKPjPKjR7ox1M3oPs+y3uRhQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi. Here's a boiled down example of something that caught me by surprise:

ag_reach_test=> CREATE TEMP TABLE foo (my_array varchar[]);
CREATE TABLE
ag_reach_test=> INSERT INTO foo (my_array) SELECT '{TEST}';
INSERT 0 1
ag_reach_test=> SELECT my_array[1],array_length(my_array,1) FROM foo;
my_array | array_length
----------+--------------
TEST | 1
(1 row)

ag_reach_test=> INSERT INTO foo (my_array) SELECT DISTINCT '{TEST}';
ERROR: column "my_array" is of type character varying[] but expression is
of type text
LINE 1: INSERT INTO foo (my_array) SELECT DISTINCT '{TEST}';
^
HINT: You will need to rewrite or cast the expression.

It's easy enough to add a cast, but I was curious if this was expected and
desired behavior. Thanks.

Ken

--
AGENCY Software
A Free Software data system
By and for non-profits
*http://agency-software.org/ <http://agency-software.org/>*
*https://agency-software.org/demo/client
<https://agency-software.org/demo/client>*
ken(dot)tanzer(at)agency-software(dot)org
(253) 245-3801

Subscribe to the mailing list
<agency-general-request(at)lists(dot)sourceforge(dot)net?body=subscribe> to
learn more about AGENCY or
follow the discussion.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G Johnston 2015-02-20 04:59:26 Re: Array string casts with SELECT but not SELECT DISTINCT
Previous Message inspector morse 2015-02-20 01:47:04 Re: stored procedure variable names