From: Marc Tardif <admin@wtbwts.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Jose Soares <jose@sferacarta.com>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] char(19) to varchar(32)
Date: Wed, 19 Jan 2000 10:56:35 +0000 (GMT)
Message-ID: <Pine.BSF.4.10.10001191051020.11067-100000@server.b0x.com> (raw)
In-Reply-To: <9884.948296503@sss.pgh.pa.us>
Actually, here's my complete rule and error message:
CREATE RULE prod_company AS ON UPDATE
TO company_base WHERE OLD.company <> NEW.company
DO UPDATE prod_base set company = NEW.company
WHERE prod_base.cid = OLD.oid;
ERROR: Type of 'company' does not match target column 'company'
company in prod_base is char(19);
company in company_baase is varchar(32);
I have solved my little problem by using substr(NEW.company, 0, 20).
Please let me know if the above error message is correct or if postgresql
should actually be casting to char(19) automatically, ie do whatever it
takes to copy whatever it can to prod_base.company.
Marc
On Wed, 19 Jan 2000, Tom Lane wrote:
> 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
>
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: admin@wtbwts.com, tgl@sss.pgh.pa.us, jose@sferacarta.com
Subject: Re: [SQL] char(19) to varchar(32)
In-Reply-To: <Pine.BSF.4.10.10001191051020.11067-100000@server.b0x.com>
References: <9884.948296503@sss.pgh.pa.us> <Pine.BSF.4.10.10001191051020.11067-100000@server.b0x.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