psql and schemas

From: Neil Conway <neilc(at)samurai(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: psql and schemas
Date: 2004-10-29 01:55:06
Message-ID: 1099014906.21161.58.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

psql's slash commands for schemas seem a little weird to me. For
example:

neilc=# \d nonexistent
Did not find any relation named "nonexistent".
neilc=# \dt nonexistent
No matching relations found.
neilc=# \dn nonexistent
List of schemas
Name | Owner
------+-------
(0 rows)

-- Is there a good reason for this inconsistency?

neilc=# create schema foo_schema;
CREATE SCHEMA
neilc=# \dn foo_schema
List of schemas
Name | Owner
------------+-------
foo_schema | neilc
(1 row)
neilc=# \dn foo_schema.
List of schemas
Name | Owner
--------------------+-------
foo_schema | neilc
information_schema | neilc
pg_catalog | neilc
pg_toast | neilc
public | neilc
(5 rows)

-- Why? (The same applies to "\dn nonexistent.")

neilc=# \d
No relations found.
neilc=# \d foo_schema.*
Did not find any relation named "foo_schema.*".

-- Why the difference in behavior? In any case, the error message is
confusing -- it suggests psql was looking for a relation with the name
"foo_schema.*", where it obviously was not:

neilc=# create table "foo_schema.*" (a int, b int);
CREATE TABLE
neilc=# \d foo_schema.*
Did not find any relation named "foo_schema.*".
neilc=# \d
List of relations
Schema | Name | Type | Owner
--------+--------------+-------+-------
public | foo_schema.* | table | neilc
(1 row)

-- When you do \d schema.*, you get the definitions of _all_ the objects
in the schema. I can see why we support this, although I can't see it
being used very often. On the other hand, I think a much more common
case would be trying to get a list of all the objects in a schema -- is
there any way to do that? \dt schema.* lists the tables in a schema, for
example, but not the other types of objects (in a similar fashion to how
"\d" displays the objects in the search path).

That's all for now :-)

-Neil

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Josh Berkus 2004-10-29 03:07:43 Re: Suggestion: additional system views
Previous Message Christopher Kings-Lynne 2004-10-29 01:32:32 Re: pg_get_serial_sequence is inconsistent