Re: Getting table name/tuple from OID - Mailing list pgsql-hackers

From uwcssa
Subject Re: Getting table name/tuple from OID
Date
Msg-id f2f562510511111952q417e0646p89d9b889fd01b5c9@mail.gmail.com
Whole thread Raw
In response to Re: Getting table name/tuple from OID  (Marek Lewczuk <newsy@lewczuk.com>)
List pgsql-hackers
Thanks for the quick reply. I made a mistake last time by asking the question:
actually, i would like to know how to get the OID from a table name or operator name.
 
For example, ">" is 512 while "="  is 96.   and some table has the magic relid of 20078, say.
How could I find out the OID by giving the (full qualified) name of a table or an operator?
 
I need this since I want to build a query plan from external and I need to know the OID
in order to manually create the query plan. Thanks.
 
 

> I am interested in the answer as well -- how to get a table name (or
> an operator name)
> from an OID.    the parser must know how to do this, but the segment
> of code is hard
> to locate.
>
CREATE OR REPLACE FUNCTION gettablename(__oid oid)
  RETURNS "varchar" AS
$BODY$
SELECT (_sna.nspname || '.' || _tna.relname) AS tableQualifiedName FROM
pg_class _tna, pg_namespace _sna WHERE _tna.oid = $1 AND _sna.oid =
_tna.relnamespace;
$BODY$
  LANGUAGE 'sql' IMMUTABLE;
ALTER FUNCTION gettablename(__oid oid) OWNER TO root;



pgsql-hackers by date:

Previous
From: Rod Taylor
Date:
Subject: Re: MERGE vs REPLACE
Next
From: Matteo Beccati
Date:
Subject: Re: MERGE vs REPLACE