pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Jose Soares <jose@sferacarta.com>
Cc: Marc Tardif <admin@wtbwts.com>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] char(19) to varchar(32)
Date: Wed, 19 Jan 2000 10:41:43 -0500
Message-ID: <9884.948296503@sss.pgh.pa.us> (raw)
In-Reply-To: <3885C3C0.2B26A120@sferacarta.com>
References: <Pine.BSF.4.10.10001181342200.7039-100000@server.b0x.com>
	<3885C3C0.2B26A120@sferacarta.com>

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



view thread (6+ messages)  latest in thread

Message-ID: <9884.948296503@sss.pgh.pa.us>
Permalink:  ../9884.948296503@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/9884.948296503@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, jose@sferacarta.com, admin@wtbwts.com
  Subject: Re: [SQL] char(19) to varchar(32)
  In-Reply-To: <9884.948296503@sss.pgh.pa.us>
  References: <Pine.BSF.4.10.10001181342200.7039-100000@server.b0x.com> <3885C3C0.2B26A120@sferacarta.com> <9884.948296503@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox