Обсуждение: Determining the OID of a certain type

Поиск
Список
Период
Сортировка

Determining the OID of a certain type

От
Carsten Kropf
Дата:
Hi *,
I wanted to ask, if there is a method to determine the oid of a certain type using the C backend interface? I need to
getaccess to a specific type for an IAM and therefore i want to construct an IndexTuple using the specified methods.
However,I need the OID of the specific type for it. I considered writing some auxiliary function that returns the OID
ofthe type using plpgsql. This works fine. However, I thought about something that I can use directly in C (server
side)to get the oid, or do I have to set up a query to the database? Querying is currently the way I go here. However,
itdoes not feel so right, to return the OID for the type I want to use, using a query. I hope, that there is some
predefinedfunction that I haven't found yet to determine the OID of some type (or relation etc). 

Best regards,
    Carsten Kropf

Re: Determining the OID of a certain type

От
Tom Lane
Дата:
Carsten Kropf <ckropf2@fh-hof.de> writes:
> I wanted to ask, if there is a method to determine the oid of a
> certain type using the C backend interface?

Starting from what?

For built-in types it's usual practice to use the #define from
pg_type.h, if there is one.  If you have a string name for the type,
there's a parser function to derive an OID, which I forget the name
of but it's probably in parse_type.c.

            regards, tom lane

Re: Determining the OID of a certain type

От
Carsten Kropf
Дата:
Thanks a lot,
basically I looked inside these functions in parse_type.c and did not find an "easy to use" application here. So I considered trying to construct the required arguments passed to typenameType. However, during the development, I found the following function: 
Oid
TypenameGetTypid(const char *typname)
which does indeed do the lookup of my particular type in the cache and system catalog tables. Thanks a lot for the hint!
Best regards
Carsten Kropf
Am 22.03.2010 um 13:18 schrieb Tom Lane:

Carsten Kropf <ckropf2@fh-hof.de> writes:
I wanted to ask, if there is a method to determine the oid of a
certain type using the C backend interface?

Starting from what?

For built-in types it's usual practice to use the #define from
pg_type.h, if there is one.  If you have a string name for the type,
there's a parser function to derive an OID, which I forget the name
of but it's probably in parse_type.c.

regards, tom lane

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Re: Determining the OID of a certain type

От
Tom Lane
Дата:
Carsten Kropf <ckropf2@fh-hof.de> writes:
> basically I looked inside these functions in parse_type.c and did not find an "easy to use" application here. So I
consideredtrying to construct the required arguments passed to typenameType. However, during the development, I found
thefollowing function:  
> Oid
> TypenameGetTypid(const char *typname)
> which does indeed do the lookup of my particular type in the cache and system catalog tables. Thanks a lot for the
hint!

Actually, parseTypeString() is what I was thinking of.  TypenameGetTypid
won't cope with schema-qualified names, nor a lot of other cases.

            regards, tom lane

Re: Determining the OID of a certain type

От
Carsten Kropf
Дата:
Oh, thanks, that's right, I see that this function I used before, searches only in the currently used schema. The usage
ofparseTypeString is comparable easy, as well, so based on your hints, I will probably use this function. 
Best regards
    Carsten Kropf
Am 22.03.2010 um 16:23 schrieb Tom Lane:

> Carsten Kropf <ckropf2@fh-hof.de> writes:
>> basically I looked inside these functions in parse_type.c and did not find an "easy to use" application here. So I
consideredtrying to construct the required arguments passed to typenameType. However, during the development, I found
thefollowing function:  
>> Oid
>> TypenameGetTypid(const char *typname)
>> which does indeed do the lookup of my particular type in the cache and system catalog tables. Thanks a lot for the
hint!
>
> Actually, parseTypeString() is what I was thinking of.  TypenameGetTypid
> won't cope with schema-qualified names, nor a lot of other cases.
>
>             regards, tom lane
>
> --
> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general