Thread: simple select question

simple select question

From
"Erol KAHRAMAN"
Date:
hi guys,

i am newbie in postgresql.  I need some help; i am trying to write like this:

select * from TABLE where IN ('value1','valeue2',....)
but is it possible to give values from file.

select * from TABLE where IN file
--
Erol KAHRAMAN
System Network Administrator

Re: simple select question

From
Richard Huxton
Date:
Erol KAHRAMAN wrote:
> hi guys,
>
> i am newbie in postgresql.  I need some help; i am trying to write like
> this:
>
> select * from TABLE where IN ('value1','valeue2',....)

You'll need to provide a column-name:
   ... WHERE mycolumn IN (...)

> but is it possible to give values from file.
>
> select * from TABLE where IN file

Not directly. You'd normally handle this in whatever language you are
using to query the database.

If you have a lot of values, you might find it useful to read them into
a temporary table.
CREATE TEMP TABLE my_values (...);
COPY my_values ... FROM <filename>;
ANALYSE my_values;
SELECT * FROM main_table JOIN my_values ON main_table_column =
my_values_column

Of course, that assumes you have your values one per line - see the
manuals for details of what COPY can handle.
--
   Richard Huxton
   Archonet Ltd

Re: simple select question

From
Ragnar
Date:
On mán, 2007-06-04 at 12:12 +0300, Erol KAHRAMAN wrote:
> hi guys,
>
> i am newbie in postgresql.  I need some help; i am trying to write
> like this:
>
> select * from TABLE where IN ('value1','valeue2',....)

... WHERE what IN (...) ?

> but is it possible to give values from file.
>
> select * from TABLE where IN file

not really. you'd have to import your file
into a table first, possibly with COPY.

gnari