From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | michael(at)kruegers(dot)email |
Cc: | Postgres General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Postgres C-API: How to get the Oid for a custom type defined in a schema outside of the current search path |
Date: | 2020-12-03 10:01:42 |
Message-ID: | CAFj8pRDH0g2JT9g457PVi7+wd=-YqktzWBcvKeen6cu5m5VQwQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi
čt 3. 12. 2020 v 10:32 odesílatel Michael Krüger <michael(at)kruegers(dot)email>
napsal:
> Dear all,
>
> I need to find out the Oid of a custom type in C programming language.
> This type is defined in a schema, outside of the standard search path, e.g.
> public.
> I know that I can call TypenameGetTypid to find out an Oid. But this is
> not working for me if the type is not in the public namespace.
> How can I query a non-public Oid? Do I have to change the search path? If
> yes how do I do it? As mentioned I need to do this with the C interface.
>
I looking to source code
Oid
TypenameGetTypidExtended(const char *typname, bool temp_ok)
{
<-->Oid><--><-->typid;
<-->ListCell *l;
<-->recomputeNamespacePath();
<-->foreach(l, activeSearchPath)
<-->{
<--><-->Oid><--><-->namespaceId = lfirst_oid(l);
<--><-->if (!temp_ok && namespaceId == myTempNamespace)
<--><--><-->continue;<-><--><-->/* do not look in temp namespace */
<--><-->typid = GetSysCacheOid2(TYPENAMENSP, Anum_pg_type_oid,
<--><--><--><--><--><--><--><-->PointerGetDatum(typname),
<--><--><--><--><--><--><--><-->ObjectIdGetDatum(namespaceId));
<--><-->if (OidIsValid(typid))
<--><--><-->return typid;
<-->}
<-->/* Not found in path */
<-->return InvalidOid;
}
You can get the value from sys cache by call GetSysCacheOid2. It can looks
like
<--><-->char<--> *schemaname;
<--><-->char<--> *typname;
<--><--><-->namespaceId = LookupExplicitNamespace(schemaname, missing_ok);
<--><--><-->if (OidIsValid(namespaceId))
<--><--><--><-->typoid = GetSysCacheOid2(TYPENAMENSP, Anum_pg_type_oid,
<--><--><--><--><--><--><--><--><--><--> PointerGetDatum(typname),
<--><--><--><--><--><--><--><--><--><--> ObjectIdGetDatum(namespaceId));
<--><--><-->else
<--><--><--><-->typoid = InvalidOid;
Regards
Pavel
> Regards,
> Michael
>
> Email: michael(at)kruegers(dot)email
>
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Krüger | 2020-12-03 10:44:48 | Re: Postgres C-API: How to get the Oid for a custom type defined in a schema outside of the current search path |
Previous Message | Michael Krüger | 2020-12-03 09:32:28 | Postgres C-API: How to get the Oid for a custom type defined in a schema outside of the current search path |