Обсуждение: imlicit varchar truncation

Поиск
Список
Период
Сортировка

imlicit varchar truncation

От
"Pavel B. Milovantsev"
Дата:
Hello.

    I meet the difficulties with insert/update commands using Postgresql
JDBC driver.

    Due to problems described previously at

> Re: value too long for type character varying(25) (http://archives.postgresql.org/pgsql-novice/2002-11/msg00166.php)

 and

>Re: ParameterMetaData getPrecision() always zero? (http://archives.postgresql.org/pgsql-jdbc/2010-01/msg00077.php)

I have to perform an additional call to connection.getMetaData().getColumns()
in order to obtain the size of inserted/updated varchar field, and either
truncate the value at the client side, or make explicit truncations as shown
at (http://www.postgresql.org/docs/9.0/static/datatype-character.html)

The question is, are there any "standard" ways to avoid this excessive
call?
    Have to say that a hand-made DB scheme caching is not the option.

Thank you in advance.
    Pavel Milovantsev.

Вложения

Re: imlicit varchar truncation

От
Sean Bowman
Дата:
On 3/21/11 8:09 AM, "Pavel B. Milovantsev" <pav@enterprisewizard.com>
wrote:

>I have to perform an additional call to
>connection.getMetaData().getColumns()
>in order to obtain the size of inserted/updated varchar field, and either
>truncate the value at the client side, or make explicit truncations as
>shown
>at (http://www.postgresql.org/docs/9.0/static/datatype-character.html)
>
>The question is, are there any "standard" ways to avoid this excessive
>call?
>    Have to say that a hand-made DB scheme caching is not the option.
>

This is how I've always done it.

Though are you saying you can't load your database schema when the
application starts and cache the lengths of all the varchars?  Is your
schema that dynamic, that it changes while the application is running?
You're on a dangerous path, my friend.

I'm not trying to be condescending, and I have no idea what the goal of
your app is so it may be appropriate, but 99.9% of the time you shouldn't
be creating new database tables or columns in your application on the fly.
 If this is the case, you might want to sit down with a database expert
and examine your strategies.  There may be a better way to model what
you're trying to accomplish and still get the performance for which you're
looking.