Re: from string to table...?

From: Richard Huxton <dev(at)archonet(dot)com>
To: will trillich <will(at)serensoft(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: from string to table...?
Date: 2001-03-23 07:53:39
Message-ID: 3ABB0103.FA63B92F@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

will trillich wrote:
>
> let's say you have the name of a table in a string.
>
> 'mytable'
>
> you also have field names, such as
>
> 'lookupfield' 'valuefield'
>
> which would be assembled like this
>
> select valuefield from mytable where lookupfield = '?'
>
> is there a way to write sql/plpgsql that'll take a varchar
> argument (table and field names) and be able to turn it into the
> appropriate query?

You can use the "EXECUTE" statement in plpgsql (v7.1) to dynamically
build a query. The catch is you can't return rows from a function. You
could use it to build a view and then query that.

Probably easiest to do in the application layer though.

- Richard Huxton

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message McMillen Tom 2001-03-23 08:18:26 Free Text Search
Previous Message Richard Huxton 2001-03-23 07:45:20 Re: JOIN