Some issues about data type convert

From: "donniehan" <donniehan(at)126(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Some issues about data type convert
Date: 2010-01-04 11:04:59
Message-ID: hhsi0q$2a11$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi guys,

I have a question about pg_cast--- data type convert.
Pg provide more data types than sql spec, such as OID.
Internal OID type is unsigned int32 and INT8 is int64.

Why pg can convert INT8 into OID implicitly while can not convert OID into INT8 implicitly?

There may be some problems when using coalesce expr. Have a look at the following case:

postgres=# create table test1(c1 OID, c2 BIGINT);
CREATE TABLE
postgres=# create view v1 as select coalesce(c1,c2) from test1;
CREATE VIEW
postgres=# \d v1
View "public.v1"
Column | Type | Modifiers
----------+------+-----------
coalesce | oid |
View definition:
SELECT COALESCE(test1.c1, test1.c2::oid) AS "coalesce"
FROM test1;

postgres=# insert into test1(c2) values(-1);
INSERT 0 1
postgres=# select * from v1;
ERROR: OID out of range

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.

Regards
-Dongni

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alban Hertroys 2010-01-04 11:57:31 Re: Insert Data Into Tables Linked by Foreign Key
Previous Message hubert depesz lubaczewski 2010-01-04 10:49:22 Re: why non-greedy modifier for one atom changes greediness of other atoms?