EXECUTE with a prepared plan and NULL

From: "sergey kapustin" <kapustin(dot)sergey(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: EXECUTE with a prepared plan and NULL
Date: 2009-01-04 20:53:46
Message-ID: cf82f1380901041253j52268ee6od8962c712cf8ca0f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello!

I'm trying to run this code in one of my stored procedures

s := 'execute prepared_plan( ' || id_engine || ',' || id_search || ',' ||
id_rsite || ')';
execute s;

where "prepared_plan" is a statement defined before with PREPARE.

The thing is, that if i one of the parameters is NULL, then string s becomes
NULL also ( because NULL||"any string" = NULL) and as a result i get this
error -

ERROR: cannot EXECUTE a null querystring
CONTEXT: PL/pgSQL function "factorize" line 148 at execute statement

how this can be solved? (I want to send NULL to the prepared statement when
one of the parameters is null)

Another small question -
Why when i remove the "execute" from the beginning of s and run it like this
-

s := 'prepared_plan( ' || id_engine || ',' || id_search || ',' || id_rsite
|| ')';
execute s;

then i get a syntax error?

Thank you!

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Adrian Klaver 2009-01-04 21:04:37 Re: How to excute dynamically a generated SQL command?
Previous Message John Zhang 2009-01-04 01:57:32 How to excute dynamically a generated SQL command?