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)));