Help with dynamic SQL - Mailing list pgsql-general

From SamPost
Subject Help with dynamic SQL
Date
Msg-id 20020902234104.19700.qmail@web40301.mail.yahoo.com
Whole thread Raw
Responses Re: Help with dynamic SQL  (Martijn van Oosterhout <kleptog@svana.org>)
List pgsql-general
I've been working on this function that processes the
results of another SQL statement passed in to it. The
function is called "tagged_results_query" and I'm
having errors near here:

sql ALIAS FOR $1;
.
.
.
FOR pid_relevancy IN EXECUTE ''SELECT page_id,
sum(relevancy) as relevancy FROM (''
    || quote_ident(sql)
    || '') AS res ''
    || quote_ident(tags_code)
    || '' GROUP BY page_id ORDER BY relevancy DESC;''
           LOOP

The problem is, I'm trying to execute the SQL
statement in the variable sql (alias for $1), but when
I use quote_ident(sql) it truncates my SQL statement
to 32 characters, and when I double-quote it
(''sql''), it uses 'sql' literally, and not the value
of the variable sql. When I quadruple-quote it
(''''sql'''') it says "parse error at or near $1".

Basically what I need is a quote_ident that doesn't
truncate at all, so I can pass in long SQL queries
(100+ chars) to be executed and formatted by my
function. Any ideas?

Thanks,

Sam Post

=====
Sam Post
Synapse Interaction Facilitator
*MyndSparqz Services*

__________________________________________________
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com

pgsql-general by date:

Previous
From: Dan Ostrowski
Date:
Subject: SET? What?
Next
From: Martijn van Oosterhout
Date:
Subject: Re: Help with dynamic SQL