From: | Thomas Hallgren <thomas(at)tada(dot)se> |
---|---|
To: | Martijn van Oosterhout <kleptog(at)svana(dot)org> |
Cc: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Question about casts |
Date: | 2006-05-18 16:07:18 |
Message-ID: | 446C9BB6.4050809@tada.se |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Martijn van Oosterhout wrote:
> On Thu, May 18, 2006 at 05:41:14PM +0200, Thomas Hallgren wrote:
>
>> Just out of curiosity (and most likely, ignorance). Why can't I cast an
>> array of strings into a string? I.e.
>>
>> thhal=# select ('{"a","b"}'::varchar[])::varchar;
>> ERROR: cannot cast type character varying[] to character varying
>>
>
> Why would you need to? What would you expect to happen? Joined with a
> seperator, no seperator, with parenthesis?
>
>
Well, let's assume I use JDBC. I write code like:
ResultSet rs = stmt.executeQuery("SELECT arrValue ...");
while(rs.next())
String v = rs.getString(1);
The tuples received by the result set contains String[]. If I let
PL/Java convert it (I don't currently), it will be according to Java
semantics. I'd like to convert it using PostgreSQL semantics instead. So
I change my statement to:
"SELECT array_out(arrValue) ..."
that works of course. What baffles me is that I cannot write
"SELECT arrValue::varchar"
> What's the benefit of a cast over a function call?
>
>
None whatsoever. But PostgreSQL enables a lot of casts for some reason
or another right? Why not this one?
> Every cast costs space and lookup time. Any user can add their own
> casts if they want, but the system generally only includes the ones
> useful to many people or those required for standards complience.
>
>
OK. I can live with that. I would have thought that casting into the
string types was something that could be hardwired since the backing
functions are mandatory.
Regards,
Thomas Hallgren
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 2006-05-18 16:08:09 | Re: pg_dump and backslash escapes |
Previous Message | Bruce Momjian | 2006-05-18 16:07:05 | Re: Compression and on-disk sorting |