Skip site navigation (1) Skip section navigation (2)

Re: [SQL] char(19) to varchar(32)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jose Soares <jose(at)sferacarta(dot)com>
Cc: Marc Tardif <admin(at)wtbwts(dot)com>, pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] char(19) to varchar(32)
Date: 2000-01-19 15:41:43
Message-ID: 9884.948296503@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-sql
Jose Soares <jose(at)sferacarta(dot)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

In response to

Responses

pgsql-sql by date

Next:From: Sevo StilleDate: 2000-01-19 16:32:23
Subject: (no subject)
Previous:From: Marc TardifDate: 2000-01-19 15:40:45
Subject: Re: [SQL] Foreign Keys, Triggers and such

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group