Re: Some issues about data type convert

From: Sam Mason <sam(at)samason(dot)me(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Some issues about data type convert
Date: 2010-01-04 15:10:51
Message-ID: 20100104151051.GW5407@samason.me.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Jan 04, 2010 at 03:55:15PM +0100, Albe Laurenz wrote:
> donniehan wrote:
> > postgres=# create table test1(c1 OID, c2 BIGINT);
> > postgres=# create view v1 as select coalesce(c1,c2) from test1;
> > postgres=# \d v1
> > SELECT COALESCE(test1.c1, test1.c2::oid) AS "coalesce"
> > FROM test1;
> >
> > Although we can define the view v1 successfully, but we can
> > not get what we want.
> > If pg can convert INT8 into OID implicitly, it seems there
> > would not be any problems.
>
> This has nothing to do with implicit or explicit casts.

Um, I think the OP is right. Notice he does:

create view v1 as select coalesce(c1,c2) from test1;

which PG interprets as:

SELECT COALESCE(test1.c1, test1.c2::oid) AS "coalesce" FROM test1;

showing that PG is auto-magically inserting a cast from BIGINT to OID.
The OP is saying that this isn't right because the cast isn't a total
function, i.e. it fails for -1 and a large number of other inputs.

I think the OP is either expecting the CREATE VIEW to fail saying types
are invalid, or to result in "c1" being cast to BIGINT.

--
Sam http://samason.me.uk/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message shulkae 2010-01-04 15:46:29 converting tables to XML and back
Previous Message Albe Laurenz 2010-01-04 14:55:15 Re: Some issues about data type convert