Re: from string to table...? - Mailing list pgsql-general

From Richard Huxton
Subject Re: from string to table...?
Date
Msg-id 3ABB0103.FA63B92F@archonet.com
Whole thread Raw
In response to from string to table...?  (will trillich <will@serensoft.com>)
Responses Re: from string to table...?
List 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

pgsql-general by date:

Previous
From: will trillich
Date:
Subject: from string to table...?
Next
From: Richard Huxton
Date:
Subject: Re: JOIN