Thread: [SQL] Get relation name form relids in postgresql
Gourav Kumar
Hi all,I am looking for a way to get the relation name from the relid or RelOptInfo data structure. Can anyone help me with this ? How can I use these to get to relation name ?--Thanks,
Gourav Kumar
--
Hi,
Thanks for the reply.
I want to be able to do that from inside the postgres code, while I am in middle of executing a Query.
Hi. Try pg_catalog.pg_stat_user_tables, there you have the relid (oid) identifier 2017-10-05 13:17 GMT-05:00 Gourav Kumar <gourav1905@gmail.com>:Hi all,I am looking for a way to get the relation name from the relid or RelOptInfo data structure. Can anyone help me with this ? How can I use these to get to relation name ?--Thanks,
Gourav Kumar
--
Hi,
Thanks for the reply.
I want to be able to do that from inside the postgres code, while I am in middle of executing a Query.
On 06-Oct-2017 7:12 AM, "Rene Romero Benavides" <rene.romero.b@gmail.com> wrote:Hi. Try pg_catalog.pg_stat_user_tables, there you have the relid (oid) identifier 2017-10-05 13:17 GMT-05:00 Gourav Kumar <gourav1905@gmail.com>:Hi all,I am looking for a way to get the relation name from the relid or RelOptInfo data structure. Can anyone help me with this ? How can I use these to get to relation name ?--Thanks,
Gourav Kumar
--
--
I did not get this part. Can you elaborate please.
Sure, you can cast the relid to regclass, or join the mentioned table.2017-10-05 21:48 GMT-05:00 Gourav Kumar <gourav1905@gmail.com>:Hi,
Thanks for the reply.
I want to be able to do that from inside the postgres code, while I am in middle of executing a Query.
On 06-Oct-2017 7:12 AM, "Rene Romero Benavides" <rene.romero.b@gmail.com> wrote:Hi. Try pg_catalog.pg_stat_user_tables, there you have the relid (oid) identifier 2017-10-05 13:17 GMT-05:00 Gourav Kumar <gourav1905@gmail.com>:Hi all,I am looking for a way to get the relation name from the relid or RelOptInfo data structure. Can anyone help me with this ? How can I use these to get to relation name ?--Thanks,
Gourav Kumar
--
--
Example:
select relid, relid::regclass from pg_stat_user_tables where relname = 'theNameOfYourTable';
I did not get this part. Can you elaborate please.
On 06-Oct-2017 8:24 AM, "Rene Romero Benavides" <rene.romero.b@gmail.com> wrote:Sure, you can cast the relid to regclass, or join the mentioned table.2017-10-05 21:48 GMT-05:00 Gourav Kumar <gourav1905@gmail.com>:Hi,
Thanks for the reply.
I want to be able to do that from inside the postgres code, while I am in middle of executing a Query.
On 06-Oct-2017 7:12 AM, "Rene Romero Benavides" <rene.romero.b@gmail.com> wrote:Hi. Try pg_catalog.pg_stat_user_tables, there you have the relid (oid) identifier 2017-10-05 13:17 GMT-05:00 Gourav Kumar <gourav1905@gmail.com>:Hi all,I am looking for a way to get the relation name from the relid or RelOptInfo data structure. Can anyone help me with this ? How can I use these to get to relation name ?--Thanks,
Gourav Kumar
--
--
--
But I can't fire a query when I am inside postgres code, while executing another query.
Sure, if you cast a field that contains a relid to the reglass type, you get the name of the relation.
Example:
select relid, relid::regclass from pg_stat_user_tables where relname = 'theNameOfYourTable';2017-10-05 21:55 GMT-05:00 Gourav Kumar <gourav1905@gmail.com>:I did not get this part. Can you elaborate please.
On 06-Oct-2017 8:24 AM, "Rene Romero Benavides" <rene.romero.b@gmail.com> wrote:Sure, you can cast the relid to regclass, or join the mentioned table.2017-10-05 21:48 GMT-05:00 Gourav Kumar <gourav1905@gmail.com>:Hi,
Thanks for the reply.
I want to be able to do that from inside the postgres code, while I am in middle of executing a Query.
On 06-Oct-2017 7:12 AM, "Rene Romero Benavides" <rene.romero.b@gmail.com> wrote:Hi. Try pg_catalog.pg_stat_user_tables, there you have the relid (oid) identifier 2017-10-05 13:17 GMT-05:00 Gourav Kumar <gourav1905@gmail.com>:Hi all,I am looking for a way to get the relation name from the relid or RelOptInfo data structure. Can anyone help me with this ? How can I use these to get to relation name ?--Thanks,
Gourav Kumar
--
--
--
But I can't fire a query when I am inside postgres code, while executing another query.
On 06-Oct-2017 8:31 AM, "Rene Romero Benavides" <rene.romero.b@gmail.com> wrote:Sure, if you cast a field that contains a relid to the reglass type, you get the name of the relation.
Example:
select relid, relid::regclass from pg_stat_user_tables where relname = 'theNameOfYourTable';2017-10-05 21:55 GMT-05:00 Gourav Kumar <gourav1905@gmail.com>:I did not get this part. Can you elaborate please.
On 06-Oct-2017 8:24 AM, "Rene Romero Benavides" <rene.romero.b@gmail.com> wrote:Sure, you can cast the relid to regclass, or join the mentioned table.2017-10-05 21:48 GMT-05:00 Gourav Kumar <gourav1905@gmail.com>:Hi,
Thanks for the reply.
I want to be able to do that from inside the postgres code, while I am in middle of executing a Query.
On 06-Oct-2017 7:12 AM, "Rene Romero Benavides" <rene.romero.b@gmail.com> wrote:Hi. Try pg_catalog.pg_stat_user_tables, there you have the relid (oid) identifier 2017-10-05 13:17 GMT-05:00 Gourav Kumar <gourav1905@gmail.com>:Hi all,I am looking for a way to get the relation name from the relid or RelOptInfo data structure. Can anyone help me with this ? How can I use these to get to relation name ?--Thanks,
Gourav Kumar
--
--
--
--