Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Dec 16, 2009 at 7:20 PM, Tom Lane <tgl@xxxxxxxxxxxxx> 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)));

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux