Re: Getting fields in a table through a query?

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Mitch Vincent <mitch(at)doot(dot)org>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Getting fields in a table through a query?
Date: 2002-02-05 02:05:00
Message-ID: 20020204180312.B82048-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Mon, 4 Feb 2002, Mitch Vincent wrote:

> How can I get the fields in a given table via an SQL query even if there are
> no records in that table? I just need the names of all the fields in a
> table -- is that even possible?

select * from pg_attribute, pg_class where attrelid=pg_class.oid and
relname='<table name>' and attnum>0;
should give you all the user columns on the table specified as <table
name>

(If you want to get system columns like oid, you can leave off the
attnum>0)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Timothy Reaves 2002-02-05 02:11:16 sequence question
Previous Message Timothy Reaves 2002-02-05 01:42:00 How to see sequences?