473,320 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

syntax to view the structure of a table

priyan
54
hi

In postgre I want to view the structure of a table . pls tell me is there any query for retrieving the structure of a table. pls help me.


thanks in advance
priyan....
Aug 4 '07 #1
13 18878
hi

In postgre I want to view the structure of a table . pls tell me is there any query for retrieving the structure of a table. pls help me.


thanks in advance
priyan....


If you are working in linux then u just give \d followed with the table name
Aug 4 '07 #2
michaelb
534 Expert 512MB
This will work on any supported OS, Linux, Windows, etc
Open the psql session and type \d or \d+

Excerpt from the manual:

\d [ pattern ]
\d+ [ pattern ]

For each relation (table, view, index, or sequence) matching the pattern, show all columns, their types, the tablespace (if not the default) and any special attributes such as NOT NULL or defaults, if any. Associated indexes, constraints, rules, and triggers are also shown, as is the view definition if the relation is a view. ("Matching the pattern" is defined below.)

The command form \d+ is identical, except that more information is displayed: any comments associated with the columns of the table are shown, as is the presence of OIDs in the table.

Note: If \d is used without a pattern argument, it is equivalent to \dtvs which will show a list of all tables, views, and sequences. This is purely a convenience measure.
See the psql man page for more information
Aug 4 '07 #3
This will work on any supported OS, Linux, Windows, etc
Open the psql session and type \d or \d+

Excerpt from the manual:

See the psql man page for more information

\d [pattern] is not working.
\d[memberphoto] is my command is correct or not.
memberphoto is my tablename please help me.........
Aug 6 '07 #4
priyan
54
\d [pattern] is not working.
\d[memberphoto] is my command is correct or not.
memberphoto is my tablename please help me.........

/d [pattern] and /d+ [pattern] is not working properly. i am getting following error
code:(sql)
select \d errorlog
error:
1.ERROR: syntax error at or near "/"
2.SQL state: 42601
3.Character: 8

this my command.
Aug 6 '07 #5
michaelb
534 Expert 512MB
code:(sql)
select \d errorlog
error:
1.ERROR: syntax error at or near "/"
2.SQL state: 42601
3.Character: 8
What you did is incorrect, of course is raises the error.
You cannot embed a metacommand in your SELECT query. Look at psql man page for reference.

You may also want to read the Posting Guidelines at the top of the forum, check out how to use the CODE tags, it'll be helpful for you future postings.
Aug 6 '07 #6
priyan
54
What you did is incorrect, of course is raises the error.
You cannot embed a metacommand in your SELECT query. Look at psql man page for reference.

You may also want to read the Posting Guidelines at the top of the forum, check out how to use the CODE tags, it'll be helpful for you future postings.

if i write like
Expand|Select|Wrap|Line Numbers
  1. /d errorlog
  2.  
also the same error is coming
Expand|Select|Wrap|Line Numbers
  1. ERROR: syntax error at or near "/"
  2. SQL state: 42601
  3. Character: 1
  4.  
Aug 6 '07 #7
michaelb
534 Expert 512MB
Have you had a chance to read the psql manual I pointed to you could've noticed the correct syntax - it's \d, not /d
Expand|Select|Wrap|Line Numbers
  1. postgres=# \d
  2.                List of relations
  3.  Schema |      Name       |   Type   |  Owner
  4. --------+-----------------+----------+----------
  5.  public | bar             | table    | Michael
  6.  public | bar_id_seq      | sequence | Michael
  7.  public | businesstab     | table    | postgres
  8.  public | components      | table    | Michael
  9.  public | foo             | table    | Michael
  10.  
  11.  
  12. postgres=# \d bar
  13.                                 Table "public.bar"
  14.  Column |         Type          |                    Modifiers
  15. --------+-----------------------+--------------------------------------------------
  16.  id     | integer               | not null default nextval('bar_id_seq'::regclass)
  17.  f1     | character varying(32) |
  18.  f2     | character varying(32) |
  19. Indexes:
  20.     "bar_pkey" PRIMARY KEY, btree (id)
  21. Triggers:
  22.     trig_audit BEFORE INSERT OR UPDATE ON bar FOR EACH ROW EXECUTE PROCEDURE ... ...
  23. postgres=#
Aug 6 '07 #8
priyan
54
Have you had a chance to read the psql manual I pointed to you could've noticed the correct syntax - it's \d, not /d
Expand|Select|Wrap|Line Numbers
  1. postgres=# \d
  2.                List of relations
  3.  Schema |      Name       |   Type   |  Owner
  4. --------+-----------------+----------+----------
  5.  public | bar             | table    | Michael
  6.  public | bar_id_seq      | sequence | Michael
  7.  public | businesstab     | table    | postgres
  8.  public | components      | table    | Michael
  9.  public | foo             | table    | Michael
  10.  
  11.  
  12. postgres=# \d bar
  13.                                 Table "public.bar"
  14.  Column |         Type          |                    Modifiers
  15. --------+-----------------------+--------------------------------------------------
  16.  id     | integer               | not null default nextval('bar_id_seq'::regclass)
  17.  f1     | character varying(32) |
  18.  f2     | character varying(32) |
  19. Indexes:
  20.     "bar_pkey" PRIMARY KEY, btree (id)
  21. Triggers:
  22.     trig_audit BEFORE INSERT OR UPDATE ON bar FOR EACH ROW EXECUTE PROCEDURE ... ...
  23. postgres=#
Expand|Select|Wrap|Line Numbers
  1. \d tablename 
  2.  
is also not working properly
Aug 7 '07 #9
michaelb
534 Expert 512MB
A complete copy-and-paste example of how \d is not working properly would be helpful.
Aug 7 '07 #10
priyan
54
A complete copy-and-paste example of how \d is not working properly would be helpful.
if i use like this
Expand|Select|Wrap|Line Numbers
  1. postgres=# \d
  2.  
the error is like this
Expand|Select|Wrap|Line Numbers
  1. ERROR: syntax error at or near "postgres"
  2. SQL state: 42601
  3. Character: 1
  4.  
if i use like this
Expand|Select|Wrap|Line Numbers
  1. \d errorlog
  2.  
Expand|Select|Wrap|Line Numbers
  1. ERROR: syntax error at or near "\"
  2. SQL state: 42601
  3. Character: 1
  4.  
please give the full details help me please
Aug 7 '07 #11
michaelb
534 Expert 512MB
if i use like this
Expand|Select|Wrap|Line Numbers
  1. postgres=# \d
  2.  
the error is like this
Expand|Select|Wrap|Line Numbers
  1. ERROR: syntax error at or near "postgres"
  2. SQL state: 42601
  3. Character: 1
  4.  
postgres=# is not a part of command, it is the psql prompt...
I still have a feeling that you were trying to pass the "\d" metacommand in your SQL query.
Aug 20 '07 #12
priyan
54
postgres=# is not a part of command, it is the psql prompt...
I still have a feeling that you were trying to pass the "\d" metacommand in your SQL query.
plese explain in detail what i have to give as a command and where i have to give it. please help me...............
Aug 21 '07 #13
michaelb
534 Expert 512MB
psql is an interactive terminal to the PostgreSQL database.
When you type psql at the prompt you get a window, where you "talk" to the database. In addition to standard SQL queries (SELECT FROM ... , UPDATE ... , CREATE TABLE ..., etc, etc) you have many special commands you can use. They called meta-commands and they all begin with back-slash.
For example
\d - display all tables and views in my database
\d tab-name - describe table tab-name
\d+ tab-name - same as above, but more details.

To exit the psql session type \q
To avoid passing extra arguments when invoking psql you can set your envoronmental variables PGUSER, PGDATA and PGDATABASE.

Sometimes you don't need to stay in the psql session, you can call psql with one command, it'll tell you what you need and exit back to the command prompt.

For example, I want to see all databases on my PostgreSQL server:
Expand|Select|Wrap|Line Numbers
  1. C:\Temp> psql -l
  2. Password: ******
  3.         List of databases
  4.    Name    |  Owner   | Encoding
  5. -----------+----------+----------
  6.  Michael   | Michael  | UTF8
  7.  postgres  | postgres | UTF8
  8.  template0 | postgres | UTF8
  9.  template1 | postgres | UTF8
  10. (4 rows)
  11.  
  12. C:\Temp>
  13.  
In a similar fashion you can call psql with a query. It will execute it and spit back the result:
Expand|Select|Wrap|Line Numbers
  1. C:\Temp> psql -c "select count(1) from  pg_ts_cfg"
  2. Password: ******
  3.  count
  4. -------
  5.      4
  6. (1 row)
  7.  
  8. C:\Temp>
  9.  
You'll find more interesting things in the psql man page
Aug 21 '07 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Nithya | last post by:
Hi I need to develop/ use a tree view. It should be displayed in a jsp page.. The structure will somewhat look like this: Root / | \
5
by: megha | last post by:
Hi I want to create a tree type structure for my folders directory in java how i can do it. I know it will be a big programming but how to start please advice.
1
by: Ex-Em-El | last post by:
can anybody give / send me an example of tree view with tables that the user can choose which one(table) to present .? like : base - table + tableName + tableName + tableName
7
by: Dimitri Furman | last post by:
What would be the correct syntax, if any, that allows updating a table variable in a statement that uses the same table variable in a correlated subquery? Here's an example: DECLARE @t table (N1...
2
by: AA Arens | last post by:
When I finished whitch the Design View and want to go back to normal view, the form does not appear. Instead of that the table appears. I only get the form when I cal it on the Switchboard. How...
1
by: wxqun | last post by:
Our company is now trying to make a "standard" of creating a base view for each user table. This initiative is suggested as a good practice by a data modeling consultant who is helping us to build...
4
by: Jan | last post by:
Have an SQL create/import script. Running this on SQL would make it create a table with some values. Can Access2003 somehow use such and SQL script? I went into SQL query view to try it out, but...
1
by: obastard | last post by:
Hi Having a problem with a ms sql 2000 server. The script below was created i SQL manager 2005 lite and gives a syntax error near '(' ALTER TABLE . ADD CONSTRAINT PRIMARY KEY CLUSTERED ()...
2
by: leopangaribuan | last post by:
hi all, could you please help me? currently i'm working using a view and a table in sql server 2000. the view has a field that sums the quantity of outgoing items grouped by date and then by item...
1
by: Aliya | last post by:
i am using asp.net & vb.net. i have a dynamic table showing list of users. i have a search feature which allows users to search for their friends. if a friend is found, i want the focus to shift to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.