Re: Anything akin to an Evaluate Statement in Postgresql?

From: A E <cooljoint(at)yahoo(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Anything akin to an Evaluate Statement in Postgresql?
Date: 2004-01-06 15:45:31
Message-ID: 20040106154531.22557.qmail@web12107.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom and Chris,

I tried to use a for in loop to execute the statement to try to get some dynamic functionality but I get "ERROR: missing ".." at end of SQL expression" what am I doing wrong?

Code:

qry := ''select * from ''|| trim(realname) ||'' where ''|| trim(searchfield) ||'' like ''''%''|| trim(searchvalue) ||''%'''''';
arrayval := string_to_array(coltoparammatch(3, talias, insertparams, insertdelimiter), '','');
for objectdefinition in execute qry loop
for i in array_lower(arrayval, 1)..array_upper(arrayval, 1) loop
qry := ''select objectdefinition.''|| arrayval[i];
for aliasvalue in execute qry loop
RAISE NOTICE ''field = %'', aliasvalue;
end loop;
end loop;
end loop;


So that everyone realizes what I am trying to do. I execute a function coltoparammatch to return a string list of field names in a given table. I am then executing a query to get a reference to the table I want to pull data from. I then loop in the array of column names and "try" to make a dynamic column reference to the recordset that the query is being held in. Alas no luck though.

TIA
Alex
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
A E writes:
> I tried to execute a dynamic sql string using the dynamic record
> column name but I getting this error: ERROR: syntax error at or near
> "into" at character 8. Does the execute statement not allow the into
> keyword

It does not :-(. The best way of getting data back from an EXECUTE'd
select is to use a FOR ... IN EXECUTE loop. See the docs.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2004-01-06 15:56:59 Re: Anything akin to an Evaluate Statement in Postgresql?
Previous Message Greg Sabino Mullane 2004-01-06 11:58:04 Re: PostgreSQL speakers needed for OSCON 2004