Getting table name/tuple from OID
Paresh Bafna schrieb:
Is there any way to retrieve table name and/or tuple values from OID of
table/tuple?
Yes.
Try
SELECT 12341234::regclass;
Where 12341234 is the OID of a table.
Otherwise try:
SELECT tableoid, * FROM table;
To get the tableoid on each row.
Chris
Paresh Bafna wrote:
Show quoted text
Is there any way to retrieve table name and/or tuple values from OID of
table/tuple?---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings
Actually I want to do this from inside the postgres code i.e. I want to
get table name and tuple values from OID of corresponding table OID and
tuple OID.
Is there any built in function in postgres code to do this?
Paresh
Christopher Kings-Lynne wrote:
Show quoted text
Try
SELECT 12341234::regclass;
Where 12341234 is the OID of a table.
Otherwise try:
SELECT tableoid, * FROM table;
To get the tableoid on each row.
Chris
Paresh Bafna wrote:
Is there any way to retrieve table name and/or tuple values from OID of
table/tuple?---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings
Hi all,
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.
thanks a lot,
Huaxin
Show quoted text
On 11/7/05, Paresh Bafna <paresh@it.iitb.ac.in> wrote:
Actually I want to do this from inside the postgres code i.e. I want to
get table name and tuple values from OID of corresponding table OID and
tuple OID.
Is there any built in function in postgres code to do this?Paresh
Christopher Kings-Lynne wrote:
Try
SELECT 12341234::regclass;
Where 12341234 is the OID of a table.
Otherwise try:
SELECT tableoid, * FROM table;
To get the tableoid on each row.
Chris
Paresh Bafna wrote:
Is there any way to retrieve table name and/or tuple values from OID of
table/tuple?---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings
On Fri, Nov 11, 2005 at 08:37:07AM -0500, huaxin zhang wrote:
Hi all,
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.
For the purposes of error messages, RelationGetRelationName() does what
you want. Otherwise maybe RelationIdGetRelation(Oid relationId). Check
out utils/cache/relcache.c for a variety of functions to extract basic
data like this.
Hope this helps,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/
Show quoted text
Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
tool for doing 5% of the work and then sitting around waiting for someone
else to do the other 95% so you can sue them.
huaxin zhang napisał(a):
Hi all,
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;
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.
Show quoted text
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;