From zdu@cs.nmsu.edu Sun Sep 1 06:09:37 2002 Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id B78EF475D0F for ; Sun, 1 Sep 2002 02:09:37 -0400 (EDT) Received: from mail.cs.nmsu.edu (mail.CS.NMSU.Edu [128.123.64.3]) by postgresql.org (Postfix) with ESMTP id DAE3C475C88 for ; Sun, 1 Sep 2002 02:09:36 -0400 (EDT) Received: from cs.nmsu.edu (pilsner [128.123.64.141]) by mail.cs.nmsu.edu (8.11.6/8.11.5) with ESMTP id g8169Qs09276 for ; Sun, 1 Sep 2002 00:09:26 -0600 (MDT) Message-ID: <3D71AF16.E4216C05@cs.nmsu.edu> Date: Sun, 01 Sep 2002 00:09:26 -0600 From: Zhidian Du Organization: NMSU X-Mailer: Mozilla 4.75 [en] (X11; U; SunOS 5.9 sun4u) X-Accept-Language: en MIME-Version: 1.0 To: "pgsql-php@postgresql.org" Subject: How can I get metadate of a table in PHP3? Content-Type: text/plain; charset=gb2312 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200209/1 X-Sequence-Number: 1456 Hi: How can I get metadate of a table in PHP3? Thanks. Zhidian Du From zdu@cs.nmsu.edu Mon Sep 2 22:23:31 2002 Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 2C720476426 for ; Mon, 2 Sep 2002 18:23:31 -0400 (EDT) Received: from bubba.NMSU.Edu (bubba.NMSU.Edu [128.123.3.39]) by postgresql.org (Postfix) with ESMTP id 5655F47641B for ; Mon, 2 Sep 2002 18:23:28 -0400 (EDT) Received: from dns1.nmsu.edu (dns1.NMSU.Edu [128.123.3.5]) by bubba.NMSU.Edu (8.10.2+Sun/8.9.0) with ESMTP id g82MNGR05641; Mon, 2 Sep 2002 16:23:17 -0600 (MDT) Received: from nestor.NMSU.Edu (nestor.NMSU.Edu [128.123.34.146]) by dns1.nmsu.edu (8.9.3/8.9.0) with ESMTP id QAA16134; Mon, 2 Sep 2002 16:23:18 -0600 (MDT) Received: from cs.nmsu.edu ([128.123.37.101]) by nestor.NMSU.Edu (AIX4.3/8.9.3/8.9.0) with ESMTP id QAA119646; Mon, 2 Sep 2002 16:23:29 -0600 Message-ID: <3D72931B.9040902@cs.nmsu.edu> Date: Sun, 01 Sep 2002 16:22:19 -0600 From: Zhidian Du User-Agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.0rc2) Gecko/20020618 Netscape/7.0b1 X-Accept-Language: en-us, en MIME-Version: 1.0 To: knut.suebert@web.de Cc: "pgsql-php@postgresql.org" Subject: Re: How can I get metadate of a table in PHP3? References: <3D71AF16.E4216C05@cs.nmsu.edu> <20020902194412.GA657@fraxinus.reticulum> Content-Type: multipart/alternative; boundary="------------000801030606030008010207" X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200209/7 X-Sequence-Number: 1462 --------------000801030606030008010207 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 8bit My meaning is how can I get all the fields name of a table? ID Name Age .... 1 John 20 2 Smith 23 ..... Get ID, Name and Age and so on. knut.suebert@web.de wrote: >Zhidian Du schrieb: > > > >>How can I get metadate of a table in PHP3? >> >> > >If you think about things like the output of "\d tablename", turn on >the logging of queries, do a "\d tablename" and watch the >logfiles. > >Somewhere I need the fieldtypes of a table named $this->table, the >query is > > $q = "SELECT a.attname, format_type(a.atttypid, a.atttypmod) > FROM pg_class c, pg_attribute a > WHERE c.relname = '".$this->table."' > AND a.attnum > 0 AND a.attrelid = c.oid > ORDER BY a.attnum"; > >which is stolen from the logs - I'll never understand it ;) > >Greetings, >Knut Sübert > >---------------------------(end of broadcast)--------------------------- >TIP 6: Have you searched our list archives? > >http://archives.postgresql.org > > > > --------------000801030606030008010207 Content-Type: text/html; charset=ISO-8859-15 Content-Transfer-Encoding: 8bit My meaning is how can I get all the fields name of a table?

ID  Name  Age ....
1  John   20
2 Smith  23
.....

Get ID, Name and Age and so on.





knut.suebert@web.de wrote:
Zhidian Du schrieb:

  
How can I get metadate of a table in PHP3?
    

If you think about things like the output of "\d tablename", turn on
the logging of queries, do a "\d tablename" and watch the
logfiles.

Somewhere I need the fieldtypes of a table named $this->table, the
query is

      $q = "SELECT a.attname, format_type(a.atttypid, a.atttypmod)
        FROM pg_class c, pg_attribute a
        WHERE c.relname = '".$this->table."'
        AND a.attnum > 0 AND a.attrelid = c.oid
        ORDER BY a.attnum";

which is stolen from the logs - I'll never understand it ;)

Greetings,
Knut Sübert

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org


  

--------------000801030606030008010207-- From knut.suebert@web.de Mon Sep 2 19:52:42 2002 Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 4C38147627D for ; Mon, 2 Sep 2002 15:52:42 -0400 (EDT) Received: from mailout08.sul.t-online.com (mailout08.sul.t-online.com [194.25.134.20]) by postgresql.org (Postfix) with ESMTP id B632547627B for ; Mon, 2 Sep 2002 15:52:41 -0400 (EDT) Received: from fwd10.sul.t-online.de by mailout08.sul.t-online.com with smtp id 17lxFZ-0004l8-08; Mon, 02 Sep 2002 21:52:41 +0200 Received: from fraxinus.reticulum (520013531845-0001@[217.225.154.119]) by fmrl10.sul.t-online.com with esmtp id 17lxFR-0DK2uuC; Mon, 2 Sep 2002 21:52:33 +0200 Received: from ks by fraxinus.reticulum with local (Exim 3.35 #1 (Debian)) id 17lx7O-0000FY-00 for ; Mon, 02 Sep 2002 21:44:14 +0200 Date: Mon, 2 Sep 2002 21:44:13 +0200 From: knut.suebert@web.de To: "pgsql-php@postgresql.org" Subject: Re: How can I get metadate of a table in PHP3? Message-ID: <20020902194412.GA657@fraxinus.reticulum> References: <3D71AF16.E4216C05@cs.nmsu.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3D71AF16.E4216C05@cs.nmsu.edu> User-Agent: Mutt/1.4i X-No-Archive: yes X-Sender: 520013531845-0001@t-dialin.net X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200209/6 X-Sequence-Number: 1461 Zhidian Du schrieb: > How can I get metadate of a table in PHP3? If you think about things like the output of "\d tablename", turn on the logging of queries, do a "\d tablename" and watch the logfiles. Somewhere I need the fieldtypes of a table named $this->table, the query is $q = "SELECT a.attname, format_type(a.atttypid, a.atttypmod) FROM pg_class c, pg_attribute a WHERE c.relname = '".$this->table."' AND a.attnum > 0 AND a.attrelid = c.oid ORDER BY a.attnum"; which is stolen from the logs - I'll never understand it ;) Greetings, Knut Sübert From scott.marlowe@ihs.com Tue Sep 3 17:12:12 2002 Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 4EF814765D4 for ; Tue, 3 Sep 2002 13:12:12 -0400 (EDT) Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) by postgresql.org (Postfix) with ESMTP id 80EDF4765ED for ; Tue, 3 Sep 2002 13:12:10 -0400 (EDT) Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) by mail1.ihs.com (8.12.4/8.12.4) with ESMTP id g83HAvHn020980; Tue, 3 Sep 2002 11:10:57 -0600 (MDT) Date: Tue, 3 Sep 2002 11:04:29 -0600 (MDT) From: "scott.marlowe" To: Zhidian Du Cc: "pgsql-php@postgresql.org" Subject: Re: How can I get metadate of a table in PHP3? In-Reply-To: <3D71AF16.E4216C05@cs.nmsu.edu> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-MailScanner: Found to be clean X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200209/8 X-Sequence-Number: 1463 On Sun, 1 Sep 2002, Zhidian Du wrote: > Hi: > > How can I get metadate of a table in PHP3? I haven't driven PHP V3 since V4 came out, so I'm not sure if these are supported, but try these commands: pg_field_name() pg_field_type() You can do a "select * from table limit 1" to get a sample row. Then use pg_num_rows() to find out how many rows you have and iterate the name and type functions over each field to find out.