[GENERAL] Automatic truncation of character values & casting to the type of a column type

2009-12-16 Thread Justin Bailey
Greetings! I am trying to avoid the old problem of inserting a 40 character string into a 20 character field. However, I'd like to avoid hard-coding the acceptable length (20). Is there a way to say "cast to the same type as a given column"? E.g., if I have tables Long and Short: CREATE TABLE Lo

[GENERAL] Automatic truncation of character values & casting to the type of a column type

2009-12-16 Thread Justin Bailey
Greetings! I am trying to avoid the old problem of inserting a 40 character string into a 20 character field. However, I'd like to avoid hard-coding the acceptable length (20). Is there a way to say "cast to the same type as a given column"? E.g., if I have tables Long and Short:  CREATE TABLE Lon

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

2009-12-17 Thread Justin Bailey
On Wed, Dec 16, 2009 at 7:20 PM, Tom Lane 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 I