Skip site navigation (1) Skip section navigation (2)

Re: Issues with Array Interface

From: Noel Rappin <nrappin(at)sockeye(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Issues with Array Interface
Date: 2002-05-30 17:12:48
Message-ID: 3CF65D90.8090905@sockeye.com (view raw or flat)
Thread:
Lists: pgsql-jdbc
Okay, let's try this...

The table def is roughly this...  It's archiving an entire days worth of
data into one row.  There are some other columns that are unimportant to
the current problem.

day    timestamp without time
time     timestamp with time zone []
value     real[]

I've tried a couple of things with the code, here's what I have now.  As
this works, the data result set generates correct values as it walks
throgh the set, but the times result set always gives the same value.

    public void addOneHistoryRow(ResultSet rs) throws SQLException {
        Array timeArray = rs.getArray("time");
        ResultSet times = timeArray.getResultSet();
        Array dataArray = rs.getArray("value");
        ResultSet data = dataArray.getResultSet();
        while (times.next()) {
            data.next();
            Number value = (Number) data.getObject(2);
            String timeString = times.getString(2);
            try {
                Timestamp time = new Timestamp(
                        inputFormat.parse(timeString).getTime());
                this.addOneDataPoint(time, value);
            } catch (ParseException e) {
                System.out.println(e);
            }
        }
        }

There's actually another issue here, which is that I had to parse the
Timestamp by hand -- I was getting an error on plain getObject() for the
time column, but that's also minor.

I've tried it a few different ways -- I tried having times be generated
with
Timestamp[] times = (Timestamp[]) timeArray.getArray();

Which had the same issue -- every enery in the array had the same value.

Thanks,

Noel


Dave Cramer wrote:

 >Noel,
 >
 >It would be helpful if you could provide sample code, and table
 >definitions (just enough to reproduce the problem) .
 >
 >Dave
 >On Thu, 2002-05-30 at 11:10, Noel Rappin wrote:
 >
 >
 >>I'm having some problems with the Array interface in 7.2, and I'm
 >>wondering if somebody can point me to a workaround.
 >>
 >>Issue 1:
 >>
 >>The array in the database is of type real[].  The code:
 >>
 >>Array dataArray = rs.getArray("value");
 >>Float[] data = (Float[]) dataArray.getArray();
 >>
 >>gives me a class cast exception.  This seems to be true no matter what I
 >>try to cast the array to (even Object[]),  When I work around by using
 >>dataArray.getResultSet(), it correctly casts the individual elements of
 >>the result to Float.  I have an analagous problem when the array is of
 >>type smallint.  Since I can work around this with the result set, it's
 >>less of a problem, but it is strange.
 >>
 >>Issue 2:
 >>
 >>The array in the database is of type timestamp with time zone [].
 >>
 >>Array timeArray = rs.getArray("time");
 >>Timestamp[] times = (Timestamp[]) timeArray.getArray();
 >>
 >>runs without a class cast exception, however every element in the array
 >>is set to the same value -- the value that would be at times[0].  This
 >>problem persists even if I use getResultSet() -- even when I next()
 >>through the array, the data value does not change.   I can't seem to
 >>access the later values in the array at all.
 >>
 >>Has anybody else seen this problem?  Any suggestions for workarounds?
 >> The data can be accessed correctly through psql, so I believe the
 >>problem must be in the driver.
 >>
 >>Thanks,
 >>
 >>Noel Rappin
 >>
 >>





Responses

pgsql-jdbc by date

Next:From: Dave CramerDate: 2002-05-30 17:33:40
Subject: Re: Big problem inserting Russian characters into Postgres
Previous:From: Edd StanleyDate: 2002-05-30 16:53:07
Subject: Big problem inserting Russian characters into Postgres using JDBC

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group