Re: Question about casts
От | Thomas Hallgren |
---|---|
Тема | Re: Question about casts |
Дата | |
Msg-id | 446C9BB6.4050809@tada.se обсуждение исходный текст |
Ответ на | Re: Question about casts (Martijn van Oosterhout <kleptog@svana.org>) |
Ответы |
Re: Question about casts
|
Список | 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
В списке pgsql-hackers по дате отправления: