Re: [SQL] char(19) to varchar(32) - Mailing list pgsql-sql

From Tom Lane
Subject Re: [SQL] char(19) to varchar(32)
Date
Msg-id 9884.948296503@sss.pgh.pa.us
Whole thread Raw
In response to Re: [SQL] char(19) to varchar(32)  (Jose Soares <jose@sferacarta.com>)
Responses Re: [SQL] char(19) to varchar(32)  (Marc Tardif <admin@wtbwts.com>)
List pgsql-sql
Jose Soares <jose@sferacarta.com> writes:
> You have to cast the varchar field as char. Example:  CAST (company AS CHAR)

> For example:

> CREATE TABLE test (
>    company varchar(32)
> );
> insert into test values('12345678901234567890123456789012');
>
> CREATE TABLE test1 (
>    company char(19)
> );
> insert into test1 (company) select cast(test.company as char);

Actually, you should get the same results with or without a cast,
because the system implicitly inserts a cast to char(19) before storing
data into test1.company.

Or at least it's supposed to.  There have been bugs in that area in
past versions.  Jose's example works as I expect --- same result
with or without cast --- but I wonder whether Marc has found a problem
in pl/pgsql's handling of this situation.  Marc, you didn't actually
say why you thought that

>> company is char(19);
>> NEW.company is varchar(32);

didn't work; what behavior are you seeing?
        regards, tom lane


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: [SQL] Bug in CEIL?
Next
From: Marc Tardif
Date:
Subject: Re: [SQL] char(19) to varchar(32)