Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2003
    Posts
    16

    Arrow Unanswered: How can i access metadata of table ie data types of each column

    how can i get the data types of the each columns in the table and no of columns with names in php scipt through ADODB componet
    thanku
    :-)
    Last edited by itsvasu; 03-25-03 at 05:57.

  2. #2
    Join Date
    Jan 2003
    Location
    Midwest
    Posts
    138
    get datatypes

    \d tablename

  3. #3
    Join Date
    May 2002
    Location
    Florida, USA
    Posts
    49
    Code:
    SELECT
            a.attnum,
            a.attname AS field,
            t.typname AS type,
            a.attlen AS length,
            a.atttypmod AS lengthvar,
            a.attnotnull AS notnull
    FROM
            pg_class c,
            pg_attribute a,
            pg_type t
    WHERE
            c.relname = 'table_name'
            and a.attnum > 0
            and a.attrelid = c.oid
            and a.atttypid = t.oid
    ORDER BY a.attnum
    Gets properties for table 'table_name', returned as rows in a db query

    Colums are: attnum | field | type | length | lengthvar | notnull (attnum, or attribute number, starts at 1)

    With PostgreSQL 7.3+ You could just make a stored procedure out of this, using the table name as the input parameter, and returning a SETOF. Then, this procedure will act as a table, returning rows:

    $sql = "SELECT getTableProps($tablename)";

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •