Thread: Bug or not?

Bug or not?

From
Guillaume Lelarge
Date:
Hi,

I received a bug report some days (arg... months) before. I tried to
work on it sometime ago and again today, but I don't find a way to be
sure it is an actual bug in pgAdmin or something we can't do much right now.

Here are some psql commands to build a database that shows this issue:

CREATE DATABASE ioguix;
\c ioguix
CREATE TABLE t1 (id serial);
CREATE TABLE t2 (LIKE t1 INCLUDING DEFAULTS);

Now, launch pgAdmin3, click on the t2 table and then on the Dependents
tab. There's nothing in the listview. I assumed I would see the
t1_id_seq sequence, as showed by the SQL:

CREATE TABLE t2
(
  id integer NOT NULL DEFAULT nextval('t1_id_seq'::regclass)
)
WITH (
  OIDS=FALSE
);

I'm not sure PostgreSQL keeps this information somewhere (at least not
on the pg_depends catalog) but it sure is able to find it:

guillaume@laptop$ psql -q ioguix
ioguix=# drop table t1;
NOTICE:  default for table t2 column id depends on sequence t1_id_seq
ERROR:  cannot drop table t1 because other objects depend on it
ASTUCE : Use DROP ... CASCADE to drop the dependent objects too.


--
Guillaume.
 http://www.postgresqlfr.org
 http://dalibo.com

Re: Bug or not?

From
Dave Page
Date:
On Wed, Mar 4, 2009 at 8:46 AM, Guillaume Lelarge
<guillaume@lelarge.info> wrote:
> Hi,
>
> I received a bug report some days (arg... months) before. I tried to
> work on it sometime ago and again today, but I don't find a way to be
> sure it is an actual bug in pgAdmin or something we can't do much right now.
>
> Here are some psql commands to build a database that shows this issue:
>
> CREATE DATABASE ioguix;
> \c ioguix
> CREATE TABLE t1 (id serial);
> CREATE TABLE t2 (LIKE t1 INCLUDING DEFAULTS);
>
> Now, launch pgAdmin3, click on the t2 table and then on the Dependents
> tab. There's nothing in the listview. I assumed I would see the
> t1_id_seq sequence, as showed by the SQL:
>
> CREATE TABLE t2
> (
>  id integer NOT NULL DEFAULT nextval('t1_id_seq'::regclass)
> )
> WITH (
>  OIDS=FALSE
> );
>
> I'm not sure PostgreSQL keeps this information somewhere (at least not
> on the pg_depends catalog) but it sure is able to find it:
>
> guillaume@laptop$ psql -q ioguix
> ioguix=# drop table t1;
> NOTICE:  default for table t2 column id depends on sequence t1_id_seq
> ERROR:  cannot drop table t1 because other objects depend on it
> ASTUCE : Use DROP ... CASCADE to drop the dependent objects too.

There are dependencies in pg_depends between the pg_attrdef row and
the sequence and the pg_attrdef row and the table. Try:

select * from pg_depend where classid = 2604; -- the oid of pg_attrdef

It seems to me that it should be relatively easy to fix, by adding
pg_sttrdef to the queries in pgObject::ShowDependencies and
pgObject::ShowDependents such that type = 'r'. Need to be careful that
the existing dependency that is shown for t1 doesn't get duplicated.

--
Dave Page
EnterpriseDB UK:   http://www.enterprisedb.com