Re: Array string casts with SELECT but not SELECT DISTINCT

From: David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Array string casts with SELECT but not SELECT DISTINCT
Date: 2015-02-20 04:59:26
Message-ID: 1424408366489-5838667.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ken Tanzer wrote
> 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.

The select resolves the distinct by converting the unknown into a text so
when it gets to the insert it is already typed in the incompatible type.
Without distinct the select leaves the value as an unknown and then passing
it to the insert coerces it to the expected array.

It's a bottom-up evaluation plan instead of top-down one. Both have merit
but it definitely seems easier to implement the bottom-up version and coerce
only when needed with the immediately available information instead of
trying to skip around between layers.

David J.

--
View this message in context: http://postgresql.nabble.com/Array-string-casts-with-SELECT-but-not-SELECT-DISTINCT-tp5838663p5838667.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Pavel Stehule 2015-02-20 05:09:20 Re: stored procedure variable names
Previous Message Ken Tanzer 2015-02-20 04:18:39 Array string casts with SELECT but not SELECT DISTINCT