Re: Re: Where is the char and varchar length in pg_catalog for function input variables

Поиск
Список
Период
Сортировка
От Kevin Grittner
Тема Re: Re: Where is the char and varchar length in pg_catalog for function input variables
Дата
Msg-id 504780D10200002500049EE5@gw.wicourts.gov
обсуждение исходный текст
Ответ на Re: Re: Where is the char and varchar length in pg_catalog for function input variables  ("David Johnston" <polobo@yahoo.com>)
Список pgsql-general
"David Johnston" <polobo@yahoo.com> wrote:

> If you want to guarantee that the INSERT will work you would need
> to write:
>
> INSERT INTO test_table VALUES ( $1::char(10), $2::varchar(20) )

Note that this will quietly cut off the tail end of the supplied
data, so it should only be used when that is desirable.  It is
generally better to throw an error than to lose data.

> whether "char" and "varchar" differ in their behavior in this
> respect I do not know.

Per the SQL standard, they both throw an error on attempts to assign
an oversized value, but allow truncation through explicit casts.

> It is generally not recommended to use "char"

Right.  It is supported because the standard specifies it and its
behavior, but the semantics of char(n) are weird and the
performance, in PostgreSQL, is generally worse for char(n) than
varchar(n) or text.

-Kevin


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

Предыдущее
От: "David Johnston"
Дата:
Сообщение: Re: Re: Where is the char and varchar length in pg_catalog for function input variables
Следующее
От: Edson Richter
Дата:
Сообщение: Re: Moving several databases into one database with several schemas