pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jose Soares <jose@sferacarta.com>
To: Marc Tardif <admin@wtbwts.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] char(19) to varchar(32)
Date: Wed, 19 Jan 2000 15:01:37 +0100
Message-ID: <3885C3C0.2B26A120@sferacarta.com> (raw)
References: <Pine.BSF.4.10.10001181342200.7039-100000@server.b0x.com>

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

view thread (6+ messages)  latest in thread

Message-ID: <3885C3C0.2B26A120@sferacarta.com>
Permalink:  ../3885C3C0.2B26A120@sferacarta.com/
Also on:    postgresql.org/message-id/3885C3C0.2B26A120@sferacarta.com

 · 

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: jose@sferacarta.com, admin@wtbwts.com
  Subject: Re: [SQL] char(19) to varchar(32)
  In-Reply-To: <3885C3C0.2B26A120@sferacarta.com>
  References: <Pine.BSF.4.10.10001181342200.7039-100000@server.b0x.com> <3885C3C0.2B26A120@sferacarta.com>

* 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