Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UzrDV-0004Mw-MJ for pgsql-sql@arkaria.postgresql.org; Thu, 18 Jul 2013 16:38:09 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1UzrDV-00083U-0T for pgsql-sql@arkaria.postgresql.org; Thu, 18 Jul 2013 16:38:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UzrDT-00083N-Uf for pgsql-sql@postgresql.org; Thu, 18 Jul 2013 16:38:08 +0000 Received: from mail03.pnet.xcon.it ([62.48.53.116]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UzrDL-0008U0-Ka for pgsql-sql@postgresql.org; Thu, 18 Jul 2013 16:38:07 +0000 Received: from localhost (av.pnet.xcon.it [10.68.1.18]) by mail03.pnet.xcon.it (Postfix) with ESMTP id 0ED28B711 for ; Thu, 18 Jul 2013 18:37:58 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at av Received: from mail03.pnet.xcon.it ([10.68.1.24]) by localhost (av.pnet.xcon.it [10.68.1.18]) (amavisd-new, port 10024) with LMTP id wU2CKAOY9S6z for ; Thu, 18 Jul 2013 18:37:39 +0200 (CEST) Received: from bnc1.pnet.xcon.it (bnc1.pnet.xcon.it [10.68.1.23]) by mail03.pnet.xcon.it (Postfix) with ESMTP id E1220B6E0 for ; Thu, 18 Jul 2013 18:37:57 +0200 (CEST) Received: from localhost (av.pnet.xcon.it [10.68.1.18]) by bnc1.pnet.xcon.it (Postfix) with ESMTP id D90CA1022E35 for ; Thu, 18 Jul 2013 18:37:57 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at av Received: from bnc1.pnet.xcon.it ([10.68.1.23]) by localhost (av.pnet.xcon.it [10.68.1.18]) (amavisd-new, port 10024) with LMTP id hCZgaY4onLJX for ; Thu, 18 Jul 2013 18:37:38 +0200 (CEST) Received: from [192.168.0.131] (unknown [83.149.163.202]) (Authenticated sender: giuseppe.broccolo@2ndquadrant.it) by bnc1.pnet.xcon.it (Postfix) with ESMTPSA id 4FA581022E23 for ; Thu, 18 Jul 2013 18:37:57 +0200 (CEST) Message-ID: <51E81A53.7040200@2ndquadrant.it> Date: Thu, 18 Jul 2013 18:39:47 +0200 From: Giuseppe Broccolo User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130623 Thunderbird/17.0.7 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: Listing table definitions by only one command References: In-Reply-To: Content-Type: multipart/alternative; boundary="------------030302010609070506080004" X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org This is a multi-part message in MIME format. --------------030302010609070506080004 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi Carla, Il 17/07/2013 17:29, Carla Goncalves ha scritto: > Hi > I would like to list the definition of all user tables by only one > command. Is there a way to *not* show pg_catalog tables when using "\d > ." in PostgreSQL 9.1.9? The simpler way similar to a "\d ." I know is a query like this (supposing you are not interested also to 'information_schema' scheme as well as 'pg_catalog', and interested only on tables list): SELECT b.table_schema, a.table_name, a.column_name, a.data_type, a.is_nullable FROM information_schema.columns a INNER JOIN (SELECT * FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND table_schema <> 'pg_catalog' AND table_schema <> 'information_schema' ORDER BY table_name) b ON a.table_name = b.table_name; This query output is a table with the same fields shown with "\dS ." command, ordered by tables name and organized as follows: table_schema | table_name | column_name | data_type | is_nullable --------------------+----------------+-------------------+-------------+-------------- your_schema | your_table | column_1 | integer | YES ... | ... | ... | ... | ... It's quite less readable than "\d." (you'll obtain just one table in output than a single table for each table name), but it is ordered by table name and could be useful. Hope it helps. Giuseppe. -- Giuseppe Broccolo - 2ndQuadrant Italy PostgreSQL Training, Services and Support giuseppe.broccolo@2ndQuadrant.it | www.2ndQuadrant.it --------------030302010609070506080004 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit
Hi Carla,

Il 17/07/2013 17:29, Carla Goncalves ha scritto:
Hi
I would like to list the definition of all user tables by only one command. Is there a way to *not* show pg_catalog tables when using "\d ." in PostgreSQL 9.1.9?

The simpler way similar to a "\d ." I know is a query like this (supposing you are not interested also to 'information_schema' scheme as well as 'pg_catalog', and interested only on tables list):

SELECT b.table_schema, a.table_name, a.column_name, a.data_type, a.is_nullable FROM information_schema.columns a INNER JOIN
(SELECT * FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND table_schema <> 'pg_catalog' AND table_schema <> 'information_schema'  ORDER BY table_name) b
ON a.table_name = b.table_name;

This query output is a table with the same fields shown with "\dS ." command, ordered by tables name and organized as follows:

    table_schema | table_name | column_name | data_type | is_nullable
   --------------------+----------------+-------------------+-------------+--------------
     your_schema |  your_table  |    column_1     |   integer   |     YES
             ...           |         ...         |          ...            |       ...       |      ...

It's quite less readable than "\d." (you'll obtain just one table in output than a single table for each table name), but it is ordered by table name and could be useful.

Hope it helps.

Giuseppe.
   


-- 
Giuseppe Broccolo - 2ndQuadrant Italy
PostgreSQL Training, Services and Support
giuseppe.broccolo@2ndQuadrant.it | www.2ndQuadrant.it
--------------030302010609070506080004--