Determining the OID of a certain type

Started by Carsten Kropfabout 16 years ago5 messagesgeneral
Jump to latest
#1Carsten Kropf
ckropf2@fh-hof.de

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 get access 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 of the 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, it does not feel so right, to return the OID for the type I want to use, using a query. I hope, that there is some predefined function that I haven't found yet to determine the OID of some type (or relation etc).

Best regards,
Carsten Kropf

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Carsten Kropf (#1)
Re: Determining the OID of a certain type

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

#3Carsten Kropf
ckropf2@fh-hof.de
In reply to: Tom Lane (#2)
Re: Determining the OID of a certain type

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:

Show quoted text

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

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Carsten Kropf (#3)
Re: Determining the OID of a certain type

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 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!

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

#5Carsten Kropf
ckropf2@fh-hof.de
In reply to: Tom Lane (#4)
Re: Determining the OID of a certain type

Oh, thanks, that's right, I see that this function I used before, searches only in the currently used schema. The usage of parseTypeString 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:

Show quoted text

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 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!

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