Waiting for 8.5 – Have \d show child tables that inherit from the specified parent

Yesterday Peter Eisentraut committed a patch, written by Damien Clochard, that modifies \d output in psql:

Have \d show child tables that inherit from the specified parent
 
As per discussion, \d shows only the number of child tables, because that
could be hundreds, when used for partitioning.  \d+ shows the actual list.
 
Author: Damien Clochard <damien@dalibo.info>

Continue reading Waiting for 8.5 – Have \d show child tables that inherit from the specified parent

Tips N’ Tricks – Generating readable reports with plain SQL

Let's say you imported some data, but it contains duplicates. You will have to handle them in some way, but to make sensible choice on how to handle it, you need more information.

So, let's start. We have table:

# \d users
                                    Table "public.users"
   Column   |           Type           |                     Modifiers
------------+--------------------------+----------------------------------------------------
 id         | integer                  | not null default nextval('users_id_seq'::regclass)
 username   | text                     |
 registered | timestamp with time zone |
Indexes:
    "users_pkey" PRIMARY KEY, btree (id)

Continue reading Tips N’ Tricks – Generating readable reports with plain SQL

Suppressing CONTEXT lines in psql

CONTEXT messages are quite informative, but when you don't need them, they can be real pain in the eyes:

psql:trees.sql:68: NOTICE:  Adding tree structures to table public.testit.
CONTEXT:  SQL function "add_tree_structure" statement 1
psql:trees.sql:68: NOTICE:  Tree table will be public.testit_tree.
CONTEXT:  SQL function "add_tree_structure" statement 1
psql:trees.sql:68: NOTICE:  Primary key in source table is: id
CONTEXT:  SQL function "add_tree_structure" statement 1

I mean – I know the context. I'm writing the sql file right now, how to disable it?

Continue reading Suppressing CONTEXT lines in psql