Feature Requests: Browse | Submit New | Admin

[#1082] DBI::DBD::Pg::Database#tables bug

Date:
2004-11-22 11:23
Priority:
5
Submitted By:
Kazuhiko (kazuhiko)
Assigned To:
Nobody (None)
Category:
None
State:
Open
Summary:
DBI::DBD::Pg::Database#tables bug

Detailed description
Though the document says that 'tables' method returns an Array of all tables and views, 'tables' method in Pg driver
only returns an Array of all tables.

A list of all tables and views can be taken by '\dtv' in psql shell, that is equivalent to the following SQL:

  SELECT n.nspname as "Schema",
    c.relname as "Name",
    CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's'
THEN 'special' END as "Type",
    u.usename as "Owner"
    FROM pg_catalog.pg_class c
    LEFT JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner
    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
    WHERE c.relkind IN ('r','v','')
    AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
    AND pg_catalog.pg_table_is_visible(c.oid)
    ORDER BY 1,2;

So I wrote a patch to fix this problem.

Add A Comment: Notepad

Please login


Followup

Message
Date: 2008-03-14 18:09
Sender: Erik Hollensbe

I'm going to enter this patch, but the context of what tables
should show is probably a hot topic of discussion amongst ruby/dbi
users, and the answer is probably in a future spec.

Counting this "closed", but moving it to "feature
requests" so I can track it for the upcoming feature
release.
Date: 2008-03-13 12:55
Sender: Erik Hollensbe

I see what you're saying.

Let me add a test that breaks this current relation (which it
seems is entirely possible) and I'll move forward.

Thanks for going through this.

-Erik
Date: 2008-03-13 05:31
Sender: Mike Pomraning

Please re-open -- the applied patch wrongly, I think, excludes
tables in pg_catalog and pg_toast schemas.

- This is a backwards compat break.
  Ouch, my code!

- Excluding pg_catalog is incorrect per se (IMHO)
  Tables are tables, even if they're information_schema or
  db-specific "system catalogs."  You're not alone
in doing
  this, Oracle.rb and FrontBase.rb do it, too -- but I
  can't say you're in good company.

- Possibly non-sensical behavior introduced.
  If I have a table "public"."pg_class",
it won't show up
  in tables() even if my schema search_path
  (pg_table_is_visible) would qualify an unadorned
  "pg_class" identifier to it in some ordinary SQL.

Recommend simply:

  SELECT c.relname
    FROM pg_catalog.pg_class c
  WHERE c.relkind IN ('r','v')
        AND
        pg_catalog.pg_table_is_visible(c.oid)
Date: 2008-02-24 20:20
Sender: Erik Hollensbe

This has been fixed and will is slated for the next release.
Date: 2008-02-23 20:58
Sender: Christopher Maujean

assigning to Erik, the patch is still broken, and it's way old.
Date: 2004-11-22 11:35
Sender: Kazuhiko 

Logged In: YES 
user_id=1446

Since I uploaded a broken patch, I upload a correct one.
Date: 2004-11-22 11:34
Sender: Kazuhiko 

Logged In: YES 
user_id=1446

Since I uploaded a broken patch, I upload a correct one.

Attached Files:

Name Description Download
ruby-dbi.patch DBI::DBD::Pg::Database#tables bugfix patch rev.2 Download

Changes:

Field Old Value Date By
assigned_toerikh2008-03-14 18:09erikh
artifact_group_idDBD2008-03-14 18:09erikh
category_idhas patch2008-03-14 18:09erikh
status_idClosed2008-03-13 12:55erikh
resolution_idNone2008-02-24 20:20erikh
status_idOpen2008-02-24 20:20erikh
category_idNone2008-02-24 20:20erikh
artifact_group_idNone2008-02-24 20:20erikh
close_date2008-02-24 20:202008-02-24 20:20erikh
priority32008-02-24 01:48erikh
File Deleted112: 2008-02-23 20:58cmaujean
File Deleted111: 2008-02-23 20:58cmaujean
assigned_tonone2008-02-23 20:58cmaujean
File Added113: ruby-dbi.patch2004-11-22 11:35kazuhiko
File Added112: ruby-dbi.patch2004-11-22 11:34kazuhiko
File Added111: ruby-dbi.patch2004-11-22 11:23kazuhiko