Обсуждение: EXECUTE with a prepared plan and NULL

Поиск
Список
Период
Сортировка

EXECUTE with a prepared plan and NULL

От
"sergey kapustin"
Дата:
<div dir="ltr">Hello!<br /><br />I'm trying to run this code in one of my stored procedures <br /><br />s := 'execute
prepared_plan(' || id_engine || ',' || id_search || ',' || id_rsite || ')';<br /> execute s;<br /><br /><br />where
"prepared_plan"is a statement defined before with PREPARE. <br /><br />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 - <br /><br
/>ERROR: cannot EXECUTE a null querystring<br />CONTEXT:  PL/pgSQL function "factorize" line 148 at execute
statement<br/><br />how this can be solved? (I want to send NULL to the prepared statement when one of the parameters
isnull)<br /><br />Another small question -<br />Why when i remove the "execute" from the beginning of s and run it
likethis - <br /><br />s := 'prepared_plan( ' || id_engine || ',' || id_search || ',' || id_rsite || ')';<br /> execute
s;<br/><br />then i get a syntax error? <br /><br /><br /><br />Thank you!<br /></div> 

Re: EXECUTE with a prepared plan and NULL

От
Tom Lane
Дата:
"sergey kapustin" <kapustin.sergey@gmail.com> writes:
> 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

quote_nullable() might help.
        regards, tom lane