Re: typecaste object to array

From: Lew <noone(at)lwsc(dot)ehost-services(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: typecaste object to array
Date: 2010-02-24 05:37:05
Message-ID: hm2du2$usu$1@news.albasani.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

beulah prasanthi wrote:
>> i [sic] am doing j2ee project .I am getting list from the user i want to
>> insert that list into array in postgres DB
>> by doing this i cannot caste an instance object pgemail to type Type
>> ARRAY
>> Can we caste the object to array .please tell me

John R Pierce wrote:
> normally, you would want to store a list as rows in a table, not as a
> SQL array. as rows, you can use various SQL operations on the data, as
> an array, it becomes a single field of a single row of a table, and is
> much harder to do anything useful with the data.
>
> as far as java typecasting, sorry, I can't help you there.

Java typecasting works only between references that are hierarchically
related, that is, one is a supertype of the other. References can always be
"upcast", Javaese for casting from a subtype to a supertype, without even use
of a cast operator. They can only be successfuly "downcast", that is, from
supertype to subtype, if the runtime type of the object matches the subtype or
is descended even further down the hierarchy from the subtype. The downcast
requires a cast operator.

So if the cast were in Java, the cast of 'pgemail' (a name that incidentally
does not conform to Java naming conventions) to an array or to
'java.sql.Array' (there is no Java type 'ARRAY' in the standard API) would
only work if the runtime type of 'pgemail' were a subtype of the respective
Java type. (The only Java supertype to either of those is 'Object', clearly
not what we're looking for here.)

For a Java 'PreparedStatement' you can set a parameter to a SQL ARRAY value
only if it's of type 'java.sql.Array' but I don't know offhand how to
construct such an object other than to retrieve it from the database, a
chicken-and-egg problem. GIYF there, I suppose.

--
Lew

In response to

Browse pgsql-general by date

  From Date Subject
Next Message dipti shah 2010-02-24 05:38:07 Re: Minor systax error but not able to resolve it...
Previous Message Thillai Selvan 2010-02-24 04:43:41 Re: [GENERAL] how do I do dump and restore without bugging with constraint?