Lists: | pgsql-jdbc |
---|
From: | Simon Temple <simon(dot)temple(at)amalto(dot)com> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | ParameterMetaData getPrecision() always zero? |
Date: | 2010-01-28 09:58:51 |
Message-ID: | 3CF1F297-BA57-4725-830E-DD282228A284@amalto.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-jdbc |
Driver: postgresql-8.4-701.jdbc4
Server: 8.4
OS: Mac OSX
<snip>
ParameterMetaData m = stat.getParameterMetaData( );
if ( null != m ) {
int colWidth = m.getPrecision( parameterIndex );
// colWidth == 0 means 'not applicable'
if ( colWidth > 0 ) {
<snip>
I have the same behaviour with many different tables.
For varchar columns I would expect to get the maximum column width. So 8 for a varchar(8).
I always get zero as a result.
I get non zero values from H2 and Derby drivers.
Is this a bug or have I missed something?
TIA
Simon Temple
From: | Kris Jurka <books(at)ejurka(dot)com> |
---|---|
To: | Simon Temple <simon(dot)temple(at)amalto(dot)com> |
Cc: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Re: ParameterMetaData getPrecision() always zero? |
Date: | 2010-01-29 21:35:50 |
Message-ID: | alpine.BSO.2.00.1001291617290.31378@leary.csoft.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-jdbc |
On Thu, 28 Jan 2010, Simon Temple wrote:
> ParameterMetaData m = stat.getParameterMetaData( );
> int colWidth = m.getPrecision( parameterIndex );
>
> For varchar columns I would expect to get the maximum column width. So 8
> for a varchar(8).
>
> I always get zero as a result.
>
This is the best the JDBC driver can do. When preparing a statement, the
server only returns the datatypes, not additional details about the size.
This is because the parameters do not always match up with a table column.
Consider "WHERE replace(col, 'a', 'bb') = ?" you won't be able to tell
the parameter size from that.
Kris Jurka