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@sss.pgh.pa.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