Обсуждение: How to get RelationName ??

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

How to get RelationName ??

От
"Ramanujam H S Iyengar"
Дата:
Hello,

How can i get the name of a relation from its Oid ?? I have seen some 
functions in utils/cache/relcache.h like RelationIdGetRelation - which gives 
Relation Node from Oid RelationSysNameGetRelation - which gives Relation 
node for only the System names.

Can anyone please tell me how to get Relation node from relation name ???

Thanks,

-Ramu

_________________________________________________________________
Contact brides & grooms FREE! http://www.shaadi.com/ptnr.php?ptnr=hmltag 
Only on www.shaadi.com. Register now!



Re: How to get RelationName ??

От
Jonathan Gardner
Дата:
On Wednesday 10 March 2004 09:58 am, Ramanujam H S Iyengar wrote:
> Hello,
>
> How can i get the name of a relation from its Oid ?? I have seen some
> functions in utils/cache/relcache.h like RelationIdGetRelation - which
> gives Relation Node from Oid RelationSysNameGetRelation - which gives
> Relation node for only the System names.
>
> Can anyone please tell me how to get Relation node from relation name ???
>

Won't you have to go get the data from the database for this? I mean 
actually execute the query:

select relname from pg_class where oid = 1234;

-- 
Jonathan Gardner
jgardner@jonathangardner.net


Re: How to get RelationName ??

От
"Ramanujam H S Iyengar"
Дата:
Hello,
Sorry for the previous confusing mail ..

iam in need of a function through which i can get a Relation Node given its 
name ..
precisely the same one equivalent to " RelationSysNameGetRelation " .. which 
works for all types of relations (system and user tables)

On Wednesday 10 March 2004 09:58 am, Ramanujam H S Iyengar wrote:
>Hello,
>
>How can i get the name of a relation from its Oid ?? I have seen some
>functions in utils/cache/relcache.h like RelationIdGetRelation - which
>gives Relation Node from Oid RelationSysNameGetRelation - which gives
>Relation node for only the System names.
>
>Can anyone please tell me how to get Relation node from relation name ???
>

Won't you have to go get the data from the database for this? I mean
actually execute the query:

Iam trying to test for some patch in the code of the Optimizer(planner) and 
so I need some C functions, which does the job. I think we must have some 
functions like the ones i have mentioned for the purpose. isin't it ??

regards,
-Ramu

>select relname from pg_class where oid = 1234;

>--
>Jonathan Gardner
>jgardner ( at ) jonathangardner ( dot ) net

_________________________________________________________________
Need a job? Get head-hunted by the best. 
http://www.naukri.com/msn/index.php?source=hotmail  Post your CV free!



Re: How to get RelationName ??

От
Tom Lane
Дата:
"Ramanujam H S Iyengar" <hals_ramu@hotmail.com> writes:
> iam in need of a function through which i can get a Relation Node given its 
> name ..
> precisely the same one equivalent to " RelationSysNameGetRelation " .. which 
> works for all types of relations (system and user tables)

The reason RelationSysNameGetRelation only works for system relations is
that it assumes the schema name is "pg_catalog".  For non-system
relations you cannot do a lookup based only on relation name, because
there's no certainty that the result is unique.

There are some functions in catalog/namespace.c that can do lookup of an
unqualified name relative to the current schema search path, if that's
what you want.

> Iam trying to test for some patch in the code of the Optimizer(planner) and 
> so I need some C functions, which does the job.

The optimizer has no need, ever, to find a relation by name; all it ever
sees are predigested relation OIDs.  So you are not making a lot of
sense here.  You certainly cannot assume that a search-path lookup is
appropriate for a relation that the optimizer is dealing with.
        regards, tom lane


Re: How to get RelationName ??

От
"Ramanujam H S Iyengar"
Дата:
>>"Ramanujam H S Iyengar" <hals_ramu ( at ) hotmail ( dot ) com> writes:
>>iam in need of a function through which i can get a Relation Node given 
>>its name ..
>>precisely the same one equivalent to " RelationSysNameGetRelation " .. 
>>which works for all types of relations (system and user tables)

>The reason RelationSysNameGetRelation only works for system relations is
>that it assumes the schema name is "pg_catalog".  For non-system
>relations you cannot do a lookup based only on relation name, because
>there's no certainty that the result is unique.


>There are some functions in catalog/namespace.c that can do lookup of an
>unqualified name relative to the current schema search path, if that's
>what you want.

Thanks a lot,
The function RelnameGetRelid(const char *) is working for me !!

>>Iam trying to test for some patch in the code of the Optimizer(planner) 
>>and so I need some C functions, which does the job.

>The optimizer has no need, ever, to find a relation by name; all it ever
>sees are predigested relation OIDs.  So you are not making a lot of
>sense here.  You certainly cannot assume that a search-path lookup is
>appropriate for a relation that the optimizer is dealing with.        regards, tom lane

Iam trying to put in some other module of optimizer that we have developed, 
which works on relation name and gives the optimal plan. Iam trying to 
convert the plans given by this(our) optimizer to the
Plan structure of PostgreSQL. So finally i have to convert the Relation 
names back to their relOids.

All this in the process of using the execution engine of Postgres for our 
optimizer module !! :-)

Thats why i was asking !!

Thanks

-Ramu

_________________________________________________________________
Take a loan. Win great prizes! Handsome prizes to be won!  Take a loan & win 
TV, Fridge & many more prizes ! http://go.msnserver.com/IN/44044.asp



Re: How to get RelationName ??

От
Tom Lane
Дата:
"Ramanujam H S Iyengar" <hals_ramu@hotmail.com> writes:
>> The optimizer has no need, ever, to find a relation by name; all it ever
>> sees are predigested relation OIDs.  So you are not making a lot of
>> sense here.  You certainly cannot assume that a search-path lookup is
>> appropriate for a relation that the optimizer is dealing with.

> Iam trying to put in some other module of optimizer that we have developed, 
> which works on relation name and gives the optimal plan. Iam trying to 
> convert the plans given by this(our) optimizer to the
> Plan structure of PostgreSQL. So finally i have to convert the Relation 
> names back to their relOids.

If your optimizer emits unqualified relation names then it is broken,
as it will never be safe to use in the presence of schemas.  People
will not want to use a database that might apply updates meant for
"a.foo" to "b.foo".
        regards, tom lane