Re: [SQL] How to query by column names

2007-01-23 Thread John Summerfield
John Summerfield wrote: Jeff Frost wrote: On Tue, 23 Jan 2007, Josh Williams wrote: From: Jeff Frost <[EMAIL PROTECTED]> On Mon, 22 Jan 2007, Richard Ray wrote: ... That's definitely part of it. I'm assuming the above is an abridged example and the OP is doing something dynamic with the q

Re: [SQL] How to query by column names

2007-01-23 Thread John Summerfield
Jeff Frost wrote: On Tue, 23 Jan 2007, Josh Williams wrote: From: Jeff Frost <[EMAIL PROTECTED]> On Mon, 22 Jan 2007, Richard Ray wrote: ... That's definitely part of it. I'm assuming the above is an abridged example and the OP is doing something dynamic with the query. The real trouble

Re: [SQL] How to query by column names

2007-01-22 Thread Josh Williams
From: Jeff Frost <[EMAIL PROTECTED]> > On Mon, 22 Jan 2007, Richard Ray wrote: ... > > #!/bin/bash > > CMD="psql -d test \"select * from t1\"" > > echo $CMD >> my_log > > eval $CMD | > > while read x; do > > do_something_with_x > > done > > > > In this example * expands to all files in the current

Re: [SQL] How to query by column names

2007-01-22 Thread Jeff Frost
On Tue, 23 Jan 2007, Josh Williams wrote: From: Jeff Frost <[EMAIL PROTECTED]> On Mon, 22 Jan 2007, Richard Ray wrote: ... That's definitely part of it. I'm assuming the above is an abridged example and the OP is doing something dynamic with the query. The real trouble is Bash likes to ex

Re: [SQL] How to query by column names

2007-01-22 Thread Jeff Frost
On Mon, 22 Jan 2007, Richard Ray wrote: On Mon, 22 Jan 2007, Jeff Frost wrote: So why are you avoiding "SELECT * FROM t1;" ? I was affeared that if I brought my total ignorance to light I would be band from the list but here goes. I work in UNIX/Linux environments. It's my habit to record m

Re: [SQL] How to query by column names

2007-01-22 Thread Richard Ray
On Mon, 22 Jan 2007, Jeff Frost wrote: So why are you avoiding "SELECT * FROM t1;" ? I was affeared that if I brought my total ignorance to light I would be band from the list but here goes. I work in UNIX/Linux environments. It's my habit to record my scripts. A simple example: #!/bin/bash

Re: [SQL] How to query by column names

2007-01-22 Thread Jeff Frost
So why are you avoiding "SELECT * FROM t1;" ? You'd probably also be happier using information_schema to get the column names. On Mon, 22 Jan 2007, Richard Ray wrote: All attributes of t1 Where (select attname from pg_attribute where attrelid = (select relfilenode from pg_class where relnam

Re: [SQL] How to query by column names

2007-01-22 Thread Richard Ray
All attributes of t1 Where (select attname from pg_attribute where attrelid = (select relfilenode from pg_class where relname = 't1') and attisdropped = false and attnum > 0) is a substitute for * On Mon, 22 Jan 2007, Jeff Frost wrote: Perhaps I should have asked this earlier. What informatio

Re: [SQL] How to query by column names

2007-01-22 Thread Jeff Frost
Perhaps I should have asked this earlier. What information are you trying to extract? On Mon, 22 Jan 2007, Richard Ray wrote: This is not exactly what I need I want to return the data in t1 On Mon, 22 Jan 2007, Jeff Frost wrote: I think this is what you're looking for Richard: SELECT attn

Re: [SQL] How to query by column names

2007-01-22 Thread Richard Ray
This is not exactly what I need I want to return the data in t1 On Mon, 22 Jan 2007, Jeff Frost wrote: I think this is what you're looking for Richard: SELECT attname FROM pg_attribute pa, pg_class pc WHERE pc.relname = 't1' AND pa.attrelid = pc.relfilenode AND pa.attisdropped IS FALSE

Re: [SQL] How to query by column names

2007-01-22 Thread Jeff Frost
I think this is what you're looking for Richard: SELECT attname FROM pg_attribute pa, pg_class pc WHERE pc.relname = 't1' AND pa.attrelid = pc.relfilenode AND pa.attisdropped IS FALSE AND pa.attnum > 0; Let me know if it doesn't do what you intended. On Mon, 22 Jan 2007, Richard R

[SQL] How to query by column names

2007-01-22 Thread Richard Ray
This may be a simple but can I create a query such as select (select attname from pg_attribute where attrelid = (select relfilenode from pg_class where relname = 't1') and attisdropped = false and attnum > 0) from t1; I get ERROR: more than one row returned by a subquery used as an expressio