Re: from string to table...?

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(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 16:12:59
Message-ID: Pine.BSF.4.21.0103230801590.46459-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2001-03-23 16:21:21 Re: Lost Trigger(s)?
Previous Message Vince Vielhaber 2001-03-23 15:48:24 Re: Call for platforms