Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 2F3622E0032 for ; Sat, 19 Apr 2008 14:56:33 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 04381-02 for ; Sat, 19 Apr 2008 14:56:29 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by developer.postgresql.org (Postfix) with ESMTP id 0BBF52E0063 for ; Sat, 19 Apr 2008 14:56:30 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.14.1/8.14.1) with ESMTP id m3JHuSC8003331 for ; Sat, 19 Apr 2008 14:56:28 -0300 (ADT) (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.14.1/8.14.1/Submit) id m3JHeXxK099636 for pgsql-sql@postgresql.org; Sat, 19 Apr 2008 14:40:33 -0300 (ADT) (envelope-from news) From: Christopher Browne X-Newsgroups: pgsql.sql Subject: Re: Desc Commnad in pgsql? Date: Sat, 19 Apr 2008 12:55:53 -0400 Organization: cbbrowne Computing Inc Lines: 82 Message-ID: <87skxh3ht2.fsf@wolfe.cbbrowne.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@news.hub.org X-message-flag: Outlook is rather hackable, isn't it? X-Home-Page: http://www.cbbrowne.com/info/ X-Affero: http://svcs.affero.net/rm.php?r=cbbrowne User-Agent: Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.21 (linux) Cancel-Lock: sha1:gxD9sL8XyIkB9VRiiSAV6v/AD3c= To: pgsql-sql@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200804/118 X-Sequence-Number: 30657 The world rejoiced as vikasraigupta@gmail.com (VG) wrote: > Hello All, > I like to know how can I achieve the same functionality that is give by desc commnad in mysql or oracle. > Also specify me the book related to pgsql as a beginner. > Presently my task is going to be communication of ruby with pgsql > Thanks in advanced. If you were referring to the usage of "desc" to indicate "descending order", as in: select * from some table order by id desc well, that's pretty standard SQL usage, and will work much as it would in MySQL(tm) or Oracle. If you're looking for ways to "describe" a table, there are two mechanisms: 1. SQL standard (probably SQL:1993) describes an "information_schema" which contains tables or views that allow querying database metadata in a fairly standard fashion. PostgreSQL supports that. 2. Probably easier and friendlier, albeit nonportable, is to use the psql "\d" command. Here's an example: cbbrowne@wolfe:~> psql ledgersmb Saturday 12:51:13 Welcome to psql 8.1.10, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help with psql commands \g or terminate with semicolon to execute query \q to quit ledgersmb=# \d acc_trans Table "public.acc_trans" Column | Type | Modifiers ----------------+---------+------------------------------------------------------------- trans_id | integer | chart_id | integer | not null transdate | date | default date('now'::text) source | text | cleared | boolean | default false fx_transaction | boolean | default false project_id | integer | memo | text | invoice_id | integer | amount | numeric | entry_id | bigint | not null default nextval('acctrans_entry_id_seq'::regclass) Indexes: "acc_trans_pkey" PRIMARY KEY, btree (entry_id) "acc_trans_chart_id_key" btree (chart_id) "acc_trans_source_key" btree (lower(source)) "acc_trans_trans_id_key" btree (trans_id) "acc_trans_transdate_key" btree (transdate) Foreign-key constraints: "$1" FOREIGN KEY (chart_id) REFERENCES chart(id) "$2" FOREIGN KEY (chart_id) REFERENCES chart(id) "$3" FOREIGN KEY (chart_id) REFERENCES chart(id) "$4" FOREIGN KEY (chart_id) REFERENCES chart(id) "acc_trans_chart_id_fkey" FOREIGN KEY (chart_id) REFERENCES chart(id) You can query the schemas for all sorts of objects, complete with tab-completion; type "\?" at the psql prompt to see all of the internal psql commands. There is a whole section entitled "Informational" that shows modifiers to \d to query various sorts of objects. For instance: \dt will list all tables \ds will list all sequences \dv will list all views and there's a further cast of ~20 variants for various different sorts of objects. -- let name="cbbrowne" and tld="gmail.com" in String.concat "@" [name;tld];; http://linuxdatabases.info/info/postgresql.html "Java and C++ make you think that the new ideas are like the old ones. Java is the most distressing thing to hit computing since MS-DOS." -- Alan Kay