Re: Automatic truncation of character values & casting to the type of a column type - Mailing list pgsql-general

From Justin Bailey
Subject Re: Automatic truncation of character values & casting to the type of a column type
Date
Msg-id a45dff840912170715t45054cd4n8fb8314019049664@mail.gmail.com
Whole thread Raw
In response to Re: Automatic truncation of character values & casting to the type of a column type  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Automatic truncation of character values & casting to the type of a column type
List 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 by date:

Previous
From: Vincenzo Romano
Date:
Subject: Re: Table Partitioning Advice Request
Next
From: Tom Lane
Date:
Subject: Re: Automatic truncation of character values & casting to the type of a column type