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

From Stephan Szabo
Subject Re: from string to table...?
Date
Msg-id Pine.BSF.4.21.0103230801590.46459-100000@megazone23.bigpanda.com
Whole thread Raw
In response to from string to table...?  (will trillich <will@serensoft.com>)
List pgsql-general
On Fri, 23 Mar 2001, 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?
>
> i can see pg_class contains table info and pg_attribute has info
> for the fields ... is there a way (oids maybe?) to direct
> postgres to the right table for a search, given the name of the
> table in a varchar string? (and if so, how? :)

Well, under 7.1, you can use EXECUTE to build query strings inside
the procedure and execute them, but you may run into return value
problems if you're trying to execute that select and return the
value.


pgsql-general by date:

Previous
From: "Jan Wessely"
Date:
Subject: Slow SELECT...IN statements
Next
From: Stephan Szabo
Date:
Subject: Re: Lost Trigger(s)?