Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I see the column names of a table?

Tags:

postgresql

So I made some tables programatically and I want to verify it's structure is what I think it is.

>Rocko=# \c Rocko
Password for user Rocko:
psql (8.4.4, server 8.4.8)
You are now connected to database "Rocko".
Rocko=# \d
            List of relations
 Schema |     Name     |   Type   | Owner
--------+--------------+----------+-------
 public | Email        | table    | Rocko
 public | Email_id_seq | sequence | Rocko
 public | Test         | table    | Rocko
 public | Test_id_seq  | sequence | Rocko
 public | User         | table    | Rocko
 public | User_id_seq  | sequence | Rocko
(6 rows)

So, for example, I want to see the columns in Test.

Rocko=# \d Test

Did not find any relation named "Test".

Wait a minute?! Did not Test just show up under "List of Relations"? What's going on here?

like image 1000
Michael Litchard Avatar asked Oct 26 '11 23:10

Michael Litchard


People also ask

How do you show column names in a table?

To get the column name of a table we use sp_help with the name of the object or table name. sp_columns returns all the column names of the object. The following query will return the table's column names: sp_columns @table_name = 'News'


1 Answers

PostgreSQL converts unquoted identifiers (such as table and column names) to lower case by default; the standard says that identifiers are supposed to be normalized to upper case but that's not important here. So, when you say this:

\d Test

PostgreSQL considers that the same as \d test. You probably have a table that was created with a quoted name:

create table "Test" ( ...

so that its name is case sensitive and must be quoted (with double quotes) every time it is referenced. So try quoting the name:

\d "Test"
like image 79
mu is too short Avatar answered Sep 21 '22 14:09

mu is too short