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

From: Jose Soares <jose(at)sferacarta(dot)com>
To: Marc Tardif <admin(at)wtbwts(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] char(19) to varchar(32)
Date: 2000-01-19 14:01:37
Message-ID: 3885C3C0.2B26A120@sferacarta.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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
>
> ************

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Nikolay Mijaylov 2000-01-19 14:05:33 Re: [SQL] Bug in CEIL?
Previous Message Mark Alliban 2000-01-19 13:26:56 Bug in CEIL?