Re: Automatic truncation of character values & casting to the type of a column type

Поиск
Список
Период
Сортировка
От Justin Bailey
Тема Re: Automatic truncation of character values & casting to the type of a column type
Дата
Msg-id a45dff840912170715t45054cd4n8fb8314019049664@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Automatic truncation of character values & casting to the type of a column type  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Automatic truncation of character values & casting to the type of a column type  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
On Wed, Dec 16, 2009 at 7:20 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Really?  Works for me, in everything back to 7.3.
>

I must be missing something, because this function fails:

  CREATE OR REPLACE FUNCTION insertShort()
  RETURNS VOID AS
  $BODY$
  DECLARE
    s Short.shortCol%TYPE;
  BEGIN
    SELECT longCol INTO s FROM Long
      WHERE char_length(longCol) > 20;
     INSERT INTO Short (shortCol) VALUES (s);
  END;

$BODY$
  LANGUAGE 'plpgsql' VOLATILE;

If s was automatically truncated, the insert would succeed, but it
fails with a "value too long" error.

p.s. I used the definitions from my prior email:

 CREATE TABLE Long (longCol varchar(40) );
 CREATE TABLE Short (shortCol varchar(20) );

INSERT INTO Long VALUES ('FOOBAR'), ('BAZ'),
(CAST('2314J1L234J21LK342JKL32J32KL4J123LK4J13L4' AS VARCHAR(40)));

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

Предыдущее
От: Vincenzo Romano
Дата:
Сообщение: Re: Table Partitioning Advice Request
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Automatic truncation of character values & casting to the type of a column type