From: | Mahendra Singh <mahi6run(at)gmail(dot)com> |
---|---|
To: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | \d is not showing global(normal) table info if we create temporary table with same name as global table |
Date: | 2020-01-02 17:59:20 |
Message-ID: | CAKYtNAqPky_rLzPWTLG76ePhT0mC-fZq-j35rmVuSAuPzfZAqQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi hackers,
While reading code and doing some testing, I found that if we create a
temporary table with same name as we created a normal(global) table, then
\d is showing only temporary table info. I think, ideally we should
display info of both the tables. Below is the example:
postgres=# create table t (a int);
CREATE TABLE
postgres=# create temporary table t (a int);
CREATE TABLE
postgres=# \d
List of relations
Schema | Name | Type | Owner
-----------+------+-------+----------
pg_temp_2 | t | table | mahendra
(1 row)
*Expected behavior:*
postgres=# \d
List of relations
Schema | Name | Type | Owner
-----------+------+-------+----------
pg_temp_2 | t | table | mahendra
public | t | table | mahendra
(2 rows)
For me, It looks like a bug.
I debugged and found that due to below code, we are showing only temp table
information.
/*
* If it is in the path, it might still not be visible; it could be
* hidden by another relation of the same name earlier in the path.
So
* we must do a slow check for conflicting relations.
*/
char *relname = NameStr(relform->relname);
ListCell *l;
visible = false;
foreach(l, activeSearchPath)
{
Oid namespaceId = lfirst_oid(l);
if (namespaceId == relnamespace)
{
/* Found it first in path */
visible = true;
break;
}
if (OidIsValid(get_relname_relid(relname, namespaceId)))
{
/* Found something else first in path */
break;
}
}
postgres=# select oid, relname , relnamespace , reltype from pg_class where
relname = 't';
oid | relname | relnamespace | reltype
-------+---------+--------------+---------
16384 | t | 2200 | 16386
16389 | t | 16387 | 16391
(2 rows)
For able example, we have 3 namespaceId in the activeSearchPath list
(16387->temporary_table, 11, 2200->noraml-table). As I can see that 16387
is the 1st oid in list, that is corresponds to temp table, we are
displaying info of temp table but when we are checking visibility of normal
table, then we exiting from list after comparing with 1st oid because 16387
is the 1st in list and that oid is valid.
If this is a bug, then please let me know. I will be happy to fix this.
Thanks and Regards
Mahendra Singh Thalor
EnterpriseDB: http://www.enterprisedb.com
From | Date | Subject | |
---|---|---|---|
Next Message | David Fetter | 2020-01-02 18:03:23 | Re: backup manifests |
Previous Message | Tom Lane | 2020-01-02 17:37:26 | Re: Clarifying/rationalizing Vars' varno/varattno/varnoold/varoattno |