Re: simple select question

From: Richard Huxton <dev(at)archonet(dot)com>
To: Erol KAHRAMAN <erol(dot)kahraman(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: simple select question
Date: 2007-06-04 09:32:18
Message-ID: 4663DC22.8030607@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Lincoln Yeoh 2007-06-04 09:41:40 Re: Numeric performances
Previous Message Enrico Sirola 2007-06-04 09:30:50 Re: table partitioning pl/pgsql helpers