Re: BUG #2395: Can't get right type oid by PQftype.

Lists: pgsql-bugs
From: "wangshj" <wangshj(at)sduept(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #2395: Can't get right type oid by PQftype.
Date: 2006-04-14 06:30:10
Message-ID: 200604140630.k3E6UAZk059778@wwwmaster.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 2395
Logged by: wangshj
Email address: wangshj(at)sduept(dot)com
PostgreSQL version: 8.1.3
Operating system: CentOS release 4.3 (Final)
Description: Can't get right type oid by PQftype.
Details:

I create a domain type testdomainoid.

CREATE DOMAIN testdomainoid int CHECK(value >20);

In my database,the type oid of testdomainoid is 16385.But PQftype return 23
for testdomainoid's type oid.How could I get the testdomainoid's type oid.

--Creating a table use domain type.
CREATE TABLE test_domain_oid ( col testdomainoid );

--Insert a value.
INSERT INTO test_domain_oid VALUES (30);

//following is my test code.
#include <iostream>
#include "libpq-fe.h"
#include <sstream>

int main(int argc, char ** argv){
PGconn * conn = PQconnectdb("");
if( CONNECTION_OK != PQstatus(conn ) )
{
std::cout << "\nCan't connecte to db\n";
return 0;
}

PGresult * r = PQexec( conn, "SELECT col FROM test_domain_oid " );
if( PGRES_TUPLES_OK == PQresultStatus(r) )
{
Oid id = PQftype( r, 0 );
int mod = PQfmod( r, 0 );
std::cout<<"\noid: " << id<<"\nmod:" << mod <<std::endl;
}
else
{
std::cout << "\nQuery failed..\n";
return 0;
}

PQclear( r );
PQfinish( conn );
};


From: Volkan YAZICI <yazicivo(at)ttnet(dot)net(dot)tr>
To: wangshj <wangshj(at)sduept(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #2395: Can't get right type oid by PQftype.
Date: 2006-04-15 15:32:58
Message-ID: 20060415153258.GA175@alamut
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

On Apr 14 06:30, wangshj wrote:
> In my database,the type oid of testdomainoid is 16385. But PQftype return 23
> for testdomainoid's type oid.

PQftype() returns the OID of the actual _type_ used in the domain.
Therefore, you get 23, OID of the int4/int type, in the above query.

> How could I get the testdomainoid's type oid.

Simply by querying pg_type catalog:

SELECT oid FROM pg_catalog.pg_type WHERE typname = 'testdomainoid';

Regards.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Volkan YAZICI <yazicivo(at)ttnet(dot)net(dot)tr>
Cc: wangshj <wangshj(at)sduept(dot)com>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #2395: Can't get right type oid by PQftype.
Date: 2006-04-15 16:19:07
Message-ID: 18521.1145117947@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Volkan YAZICI <yazicivo(at)ttnet(dot)net(dot)tr> writes:
> On Apr 14 06:30, wangshj wrote:
>> In my database,the type oid of testdomainoid is 16385. But PQftype return 23
>> for testdomainoid's type oid.

> PQftype() returns the OID of the actual _type_ used in the domain.
> Therefore, you get 23, OID of the int4/int type, in the above query.

Yeah, this is considered a feature not a bug. In fact the original
implementation just returned the domain's OID, and that was objected
to because most client programs wouldn't recognize it.

regards, tom lane


From: 姜维 <jw(at)sduept(dot)com>
To:
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #2395: Can't get right type oid by PQftype.
Date: 2006-04-16 00:52:53
Message-ID: 44419565.4080401@sduept.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Tom Lane 写道:

> > Yeah, this is considered a feature not a bug. In fact the original
> > implementation just returned the domain's OID, and that was objected
> > to because most client programs wouldn't recognize it.
> >
> >
>
How to disable this feature ?