From: | joshua <jzuellig(at)arbormetrix(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Implicit casts to array types |
Date: | 2012-12-14 15:16:35 |
Message-ID: | 1355498195133-5736582.post@n5.nabble.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
I'm trying to create an implicit cast from an unknown type into a text array
type by creating a simple array of size 1. e.g.
create function textarray(unknown)
returns text[]
as 'select ARRAY[$1::text];'
language sql
immutable;
create cast (unknown as text[]) with function textarray(unknown) as
implicit;
However, when I try to use this, the planner doesn't use the implicit cast.
Instead it still tries to cast 'a' directly to a text[] and complains that
it's not formatted as '{a}' (ERROR: array value must start with "{" or
dimension information)
I added an additional parallel cast from text to text[]:
create function textarray(text)
returns text[]
as 'select ARRAY[$1];'
language sql
immutable;
create cast (text as text[]) with function textarray(text) as implicit;
Now, if I explicitly cast 'a'::text the implicit cast to text[] fires.
However, this doesn't help because I need all the implicit casts to fire
since this is intended to be used by COPY FROM.
I tried adding an implicit cast from unknown to text to try to get
unknown->text->text[], but that didn't work either (same error as first
attempt).
Is there something special about the unknown data type that I'm unaware of?
I don't understand why it worked for text but not for unknown.
--
View this message in context: http://postgresql.1045698.n5.nabble.com/Implicit-casts-to-array-types-tp5736582.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.
From | Date | Subject | |
---|---|---|---|
Next Message | James B. Byrne | 2012-12-14 15:21:01 | Re: Problem starting PG-9.2 on non-default port |
Previous Message | Tom Lane | 2012-12-14 15:15:59 | Re: JDBC to load UTF8@psql to latin1@mysql |