public inbox for [email protected]
help / color / mirror / Atom feedFrom: Akshay Joshi <[email protected]>
To: Ashesh Vashi <[email protected]>
Cc: pgadmin-support <[email protected]>
Cc: JasmineLiu <[email protected]>
Subject: Re: Error about inherited table of column in pgadmin1.20.0
Date: Fri, 16 Oct 2015 17:40:38 +0530
Message-ID: <CANxoLDdHpY5j-3zxCo+XU7Qu93PEouJhg2Y4vk+bSd_Cpqn7Dw@mail.gmail.com> (raw)
In-Reply-To: <CAG7mmoz6oxmEdvMgMD4wKcZDUaWByzfz2smFybr6UAyT=f4bmA@mail.gmail.com>
References: <[email protected]>
<CAG7mmoz6oxmEdvMgMD4wKcZDUaWByzfz2smFybr6UAyT=f4bmA@mail.gmail.com>
List-Unsubscribe: <mailto:[email protected]?body=unsub%20pgadmin-support>
Hi Ashesh
On Thu, Oct 15, 2015 at 1:51 PM, Ashesh Vashi <[email protected]
> wrote:
> On Thu, Oct 15, 2015 at 11:15 AM, JasmineLiu <[email protected]>
> wrote:
>
>> Hi, all !
>>
>> This is Liu Yuanyuan.
>> I find the inherited table of column shown in pgadmin 1.20.0, sometimes
>> isn’t right. That should be a bug.
>> Hope someone to do something about this problem!
>> Here is my example:
>>
>> First I execute the following sql in pgadmin 1.20.0 by query tool:
>> create schema test;
>> create table test.a1(id int);
>> create table test.a2(id int, name varchar);
>> create table test.a3(age int);
>> create table test.aa() inherits(test.a1,test.a2,test.a3);
>>
>>
>> Then in main view of pgadmin 1.20.0:
>> It shows the column age is inherited from table test.a2, this is not
>> right.
>> <http://postgresql.nabble.com/file/n5870044/1.jpg;
>> <http://postgresql.nabble.com/file/n5870044/2.jpg;
>>
> Looks like a bug to me.
>
> Akshay,
>
> Can you please take a look at it?
>
I have fixed the issue, attached is the patch file. Can you please
review it and if it looks good can you please commit the code.
>
> --
>
> Thanks & Regards,
>
> Ashesh Vashi
> EnterpriseDB INDIA: Enterprise PostgreSQL Company
> <http://www.enterprisedb.com;
>
>
> *http://www.linkedin.com/in/asheshvashi*
> <http://www.linkedin.com/in/asheshvashi;
>
>
>>
>> I also check the code of pgadmin 1.20.0, I think the method to specify the
>> inherited table of columns is not correct,especially when the inherited
>> tables have same column.
>>
>> Thanks and hope to hear from you soon!
>>
>> Best wishes!
>> Liu Yuanyuan
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://postgresql.nabble.com/Error-about-inherited-table-of-column-in-pgadmin1-20-0-tp5870044.html
>> Sent from the PostgreSQL - pgadmin support mailing list archive at
>> Nabble.com.
>>
>>
>> --
>> Sent via pgadmin-support mailing list ([email protected])
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgadmin-support
>>
>
>
--
*Akshay Joshi*
*Principal Software Engineer *
*Phone: +91 20-3058-9517Mobile: +91 976-788-8246*
--
Sent via pgadmin-support mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-support
Attachments:
[application/octet-stream] Fixed_Inherited_Table.patch (3.9K, 3-Fixed_Inherited_Table.patch)
download | inline diff:
diff --git a/pgadmin/include/schema/pgColumn.h b/pgadmin/include/schema/pgColumn.h
index fca8456..9630794 100644
--- a/pgadmin/include/schema/pgColumn.h
+++ b/pgadmin/include/schema/pgColumn.h
@@ -15,6 +15,8 @@
// App headers
#include "pgTable.h"
+WX_DECLARE_STRING_HASH_MAP(wxString, inheritHashMap);
+
class pgCollection;
class pgColumnFactory : public pgTableObjFactory
diff --git a/pgadmin/schema/pgColumn.cpp b/pgadmin/schema/pgColumn.cpp
index b3796e2..c13b13e 100644
--- a/pgadmin/schema/pgColumn.cpp
+++ b/pgadmin/schema/pgColumn.cpp
@@ -546,17 +546,38 @@ pgObject *pgColumnFactory::CreateObjects(pgCollection *coll, ctlTree *browser, c
pgColumn *column = 0;
pgDatabase *database = collection->GetDatabase();
wxString sql;
- int currentcol;
- int currentlimit;
-
- // grab inherited tables
- sql = wxT("SELECT inhparent::regclass AS inhrelname,\n")
- wxT(" (SELECT count(*) FROM pg_attribute WHERE attrelid=inhparent AND attnum>0) AS colscount\n")
- wxT(" FROM pg_inherits\n")
- wxT(" WHERE inhrelid = ") + collection->GetOidStr() + wxT("::oid\n")
- wxT(" ORDER BY inhseqno");
+ inheritHashMap inhMap;
+
+ // grab inherited tables with attibute names
+ sql = wxT(" SELECT inhparent::regclass AS inhrelname, a.attname AS attrname FROM pg_inherits i\n")
+ wxT(" LEFT JOIN pg_attribute a ON (attrelid = inhparent AND attnum > 0)\n")
+ wxT(" WHERE inhrelid = ") + collection->GetOidStr() + wxT("::oid\n")
+ wxT(" ORDER BY inhseqno");
pgSet *inhtables = database->ExecuteSet(sql);
+ if (inhtables)
+ {
+ while (!inhtables->Eof())
+ {
+ wxString attrName = inhtables->GetVal(wxT("attrname"));
+ wxString inhrelName = inhtables->GetVal(wxT("inhrelname"));
+
+ // Check attribute name is already exists in hash map
+ inheritHashMap::iterator it = inhMap.find(attrName);
+ if ( it != inhMap.end())
+ {
+ wxString &relName = it->second;
+ relName += wxT(", ") + inhrelName;
+ }
+ else
+ inhMap[attrName] = inhrelName;
+
+ inhtables->MoveNext();
+ }
+
+ delete inhtables;
+ }
+
wxString systemRestriction;
if (!settings->GetShowSystemObjects())
systemRestriction = wxT("\n AND att.attnum > 0");
@@ -604,17 +625,10 @@ pgObject *pgColumnFactory::CreateObjects(pgCollection *coll, ctlTree *browser, c
pgSet *columns = database->ExecuteSet(sql);
if (columns)
{
- currentcol = 0;
- if (inhtables && !inhtables->Eof())
- {
- currentlimit = inhtables->GetLong(wxT("colscount"));
- }
while (!columns->Eof())
{
- if (columns->GetLong(wxT("attnum")) > 0) // ignore system columns before inherited columns
- currentcol++;
-
- column = new pgColumn(collection->GetTable(), columns->GetVal(wxT("attname")));
+ wxString attrName = columns->GetVal(wxT("attname"));
+ column = new pgColumn(collection->GetTable(), attrName);
column->iSetAttTypId(columns->GetOid(wxT("atttypid")));
column->iSetColNumber(columns->GetLong(wxT("attnum")));
@@ -665,18 +679,10 @@ pgObject *pgColumnFactory::CreateObjects(pgCollection *coll, ctlTree *browser, c
column->iSetTableName(columns->GetVal(wxT("relname")));
column->iSetInheritedCount(columns->GetLong(wxT("attinhcount")));
- if (inhtables)
- {
- if (currentcol > currentlimit)
- {
- inhtables->MoveNext();
- if (!inhtables->Eof())
- currentlimit += inhtables->GetLong(wxT("colscount"));
- }
-
- if (!inhtables->Eof())
- column->iSetInheritedTableName(inhtables->GetVal(wxT("inhrelname")));
- }
+ // Check whether the attribute is inherited
+ inheritHashMap::iterator it = inhMap.find(attrName);
+ if (it != inhMap.end())
+ column->iSetInheritedTableName(it->second);
column->iSetIsLocal(columns->GetBool(wxT("attislocal")));
column->iSetAttstattarget(columns->GetLong(wxT("attstattarget")));
@@ -711,9 +717,10 @@ pgObject *pgColumnFactory::CreateObjects(pgCollection *coll, ctlTree *browser, c
break;
}
- delete inhtables;
delete columns;
}
+
+ inhMap.clear();
return column;
}
view thread (7+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected]
Subject: Re: Error about inherited table of column in pgadmin1.20.0
In-Reply-To: <CANxoLDdHpY5j-3zxCo+XU7Qu93PEouJhg2Y4vk+bSd_Cpqn7Dw@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox