I'm not able to run this unless I'm the Postgres super user. But if I run it as such, it tells me that cast already exists anyway.
"If DISTINCT is specified, all duplicate rows are removed from the result set..."
CREATE CAST (text AS varchar) WITH INOUT AS IMPLICIT;
ERROR: cast from type text to type character varying already exists
Of course this will work fine:
INSERT INTO foo (my_array) SELECT DISTINCT '{TEST}'::varchar[];
I was mostly surprised by having DISTINCT added to a SELECT make things break. It may be too obscure an issue to be worth adding, but nothing on the DISTINCT documentation suggests this possibility.
Cheers,
Ken
On Fri, Feb 20, 2015 at 6:30 PM, sridhar bamandlapally <sridhar.bn1@xxxxxxxxx> wrote:
>>>ERROR: column "my_array" is of type character varying[] but _expression_ is of type textplease try this below, may be this should helpCREATE CAST (text AS varchar) WITH INOUT AS IMPLICIT;just for info:actually this should be available in defaultOn Fri, Feb 20, 2015 at 9:48 AM, Ken Tanzer <ken.tanzer@xxxxxxxxx> wrote: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 TABLEag_reach_test=> INSERT INTO foo (my_array) SELECT '{TEST}';INSERT 0 1ag_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 textLINE 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 SoftwareA Free Software data systemBy and for non-profitslearn more about AGENCY orfollow the discussion.
AGENCY Software
A Free Software data system
By and for non-profits
(253) 245-3801
learn more about AGENCY or
follow the discussion.