Re: generating dynamic queries using pl/pgsql

From: Sean Davis <sdavis2(at)mail(dot)nih(dot)gov>
To: sarlav kumar <sarlavk(at)yahoo(dot)com>
Cc: pgsqlnovice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: generating dynamic queries using pl/pgsql
Date: 2005-01-20 17:50:52
Message-ID: D3DEBB8D-6B0B-11D9-9D53-000D933565E8@mail.nih.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice


On Jan 20, 2005, at 12:40 PM, sarlav kumar wrote:

> >Yes, it's possible.
>
> >http://www.postgresql.org/docs/7.4/interactive/plpgsql-
> statements.html#PLPGSQL->STATEMENTS-EXECUTING-DYN
> >The manual has some great information.
>  
> I read through the manual. But I am still not clear how to actually
> generate the "queries" dynamically. In my case, some of the
> "select queries" that I want to dynamically generate have joins and
> some of the "select queries" are just from one table.
>

The point of section 37.6.4 (see the manual again) is that you can
build a query from a combination of text and variables. If you have
pieces of your query, you need to build up the full query using the ||
operator (concatenation). Then you can EXECUTE it.

As for "dumping" the table, look at:

http://www.postgresql.org/docs/7.4/interactive/sql-copy.html

You can use COPY to do this.

HTH,
Sean

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Akbar 2005-01-20 17:56:52 Re: password authentication always failed
Previous Message sarlav kumar 2005-01-20 17:40:48 Re: generating dynamic queries using pl/pgsql