Received: from bologna.nettuno.it (bologna.nettuno.it [193.43.2.1]) by hub.org (8.9.3/8.9.3) with ESMTP id IAA62562 for ; Wed, 19 Jan 2000 08:59:24 -0500 (EST) (envelope-from jose@sferacarta.com) Received: from proxy.sferacarta.com (sfcabop1.nettuno.it [193.207.10.213]) by bologna.nettuno.it (8.9.3/8.9.3/NETTuno 4.1) with ESMTP id OAA07215; Wed, 19 Jan 2000 14:59:19 +0100 (MET) Received: from rosso.sferacarta.com (sferacarta.com) [10.20.30.5] by proxy.sferacarta.com with esmtp (Exim 2.05 #1 (Debian)) id 12AwYt-0005df-00; Wed, 19 Jan 2000 14:58:19 +0000 Message-ID: <3885C3C0.2B26A120@sferacarta.com> Date: Wed, 19 Jan 2000 15:01:37 +0100 From: Jose Soares X-Mailer: Mozilla 4.6 [en] (WinNT; I) X-Accept-Language: en MIME-Version: 1.0 To: Marc Tardif CC: pgsql-sql@postgresql.org Subject: Re: [SQL] char(19) to varchar(32) References: Content-Type: multipart/alternative; boundary="------------C39E943F9E730B9AF39C60F7" --------------C39E943F9E730B9AF39C60F7 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit 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); select * from test; company -------------------------------- 12345678901234567890123456789012 (1 row) select * from test1; company ------------------- 1234567890123456789 (1 row) José Marc Tardif wrote: > I have created a rule to update a char(19) field from a varchar(32) field. > I don't mind if half the field is cut out, I just want to copy the first > 19 characters. Here's what I have > ... update products set company=NEW.company; > > company is char(19); > NEW.company is varchar(32); > > Any suggestions on making this work? > Marc > > ************ --------------C39E943F9E730B9AF39C60F7 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit 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);

select * from test;
                         company
--------------------------------
12345678901234567890123456789012
(1 row)

select * from test1;
            company
-------------------
1234567890123456789
(1 row)
 

José
 

Marc Tardif wrote:

I have created a rule to update a char(19) field from a varchar(32) field.
I don't mind if half the field is cut out, I just want to copy the first
19 characters. Here's what I have
... update products set company=NEW.company;

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

Any suggestions on making this work?
Marc

************

--------------C39E943F9E730B9AF39C60F7--