Skip site navigation (1) Skip section navigation (2)

Re: EXECUTE query INTO problem

From: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: EXECUTE query INTO problem
Date: 2008-11-25 21:16:59
Message-ID: 20081125211659.GA12210@tux (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
Tk421 <vrobador(at)gmail(dot)com> schrieb:

>    I've got a problem with a function: It receives two parameters, the  
> first, the table name, and the second, a where condition. The function  
> looks like this:
>       cod bigint;
>       query TEXT;
>    BEGIN
>       query = 'SELECT codigo FROM ' || $1 || ' WHERE ' || $2;
>       EXECUTE query INTO cod;
>       ·
>       ·
>       ·
>    END;
>    I've alwais get the same error, in the EXECUTE sentence: it says:  
> Error at or near NULL at character X

Wild guess: one or both parameters contains nothing, NULL. If you concat
a string with NULL, the result is NULL. And you can't execute a

>    I've also tried declaring cod as row, but the error is the same.
>    Anybody can help me?

Please show us the complete function and how do you call this function.

Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."   (unknown)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°

In response to

pgsql-sql by date

Next:From: Pawel SochaDate: 2008-11-25 22:07:43
Subject: Re: EXECUTE query INTO problem
Previous:From: Tk421Date: 2008-11-25 20:58:18
Subject: EXECUTE query INTO problem

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group