Re: PSQL Data Type: text vs. varchar(n)

Поиск
Список
Период
Сортировка
От Chris Travers
Тема Re: PSQL Data Type: text vs. varchar(n)
Дата
Msg-id 442CBD31.4030105@metatrontech.com
обсуждение исходный текст
Ответ на Re: PSQL Data Type: text vs. varchar(n)  (Chris <dmagick@gmail.com>)
Список pgsql-general
Chris wrote:

> kurt _ wrote:
>
>> I am having a problem with Sun Java Studio Creator because the latest
>> version of the JDBC driver returns a field length of -1 for text fields.
>>
>> My question:  Is a text field just a varchar(Integer.MAX_VALUE)?  If
>> I want to use the data binding part of the SJSC tool I will need to
>> convert my text fields to some standard SQL data type.  I understand
>> that varchar just stores the actual length of the field, and not the
>> padded white space.  Would anyone recommend for or against creating a
>> field of varchar(Integer.MAX_VALUE)?  Will PostgreSQL choke on that?
>> If against, how is text implemented and how can I represent a
>> variable-length String in a SQL standard format?
>
>
> varchar has a max of 255 characters, so yeh it'll choke using
> integer.max_value.

Ummm, No.  See below.

>
>
> http://www.postgresql.org/docs/8.1/interactive/datatype-character.html
> has details on how string fields are stored and the differences.
>
 From that page:
"In any case, the longest possible character string that can be stored
is about 1 GB. (The maximum value that will be allowed for /n/ in the
data type declaration is less than that. It wouldn't be very useful to
change this because with multibyte character encodings the number of
characters and bytes can be quite different anyway. If you desire to
store long strings with no specific upper limit, use text or character
varying without a length specifier, rather than making up an arbitrary
length limit.)"

If 255 characters takes up 1GB if space, you are in trouble.  Last I
checked, text and varchar() were largely identical.  THe only difference
is that you have the ability to define an arbitrary limit to the varchar
field.

Best Wishes,
Chris Travers
Metatron Technology Consulting

Вложения

В списке pgsql-general по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: FAQ 1.1
Следующее
От: Tom Lane
Дата:
Сообщение: Re: PSQL Data Type: text vs. varchar(n)