Re: Help with dynamic SQL - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: Help with dynamic SQL
Date
Msg-id 20020903100747.A17354@svana.org
Whole thread Raw
In response to Help with dynamic SQL  (SamPost <everywhereboy@yahoo.com>)
List pgsql-general
I don't know anything about SQL functions, but it seems to me for the
behaviour indicated that quote_ident is for quoting *identifiers* not
queries not identifiers in queries. Try leaving the quote_ident out
altogether.

Hope this helps,

On Mon, Sep 02, 2002 at 04:41:04PM -0700, SamPost wrote:
> 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
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly

--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> There are 10 kinds of people in the world, those that can do binary
> arithmetic and those that can't.

pgsql-general by date:

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