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/