Re: ParameterMetaData getPrecision() always zero?

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
Thread:
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

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kris Jurka 2010-01-29 21:43:31 Re: Object types and ResultSets (java.sql.Struct)
Previous Message Kris Jurka 2010-01-29 21:17:25 Re: LIKE and ESCAPING in JDBC Select Statement