Обсуждение: function query error: column does not exist

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

function query error: column does not exist

От
giozh
Дата:
i've a function takes as argument some values of few types, and make some
INSERT operation using that values.
I've occour an error while calling that function, the error is on a varchar
variable.

this is the insert code:

>EXECUTE 'INSERT INTO table VALUES('||value1||','[...]','||value_char||')';

and the error is on value_char. pg told me that "column does not exist".
Why?




--
View this message in context:
http://postgresql.1045698.n5.nabble.com/function-query-error-column-does-not-exist-tp5763460.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


Re: function query error: column does not exist

От
Alban Hertroys
Дата:
On 11 July 2013 11:01, giozh <giozh@yahoo.it> wrote:
this is the insert code:

>EXECUTE 'INSERT INTO table VALUES('||value1||','[...]','||value_char||')';

and the error is on value_char. pg told me that "column does not exist".

A few suggestions:

1. Post a statement that actually matches your problem statement. What you posted can't possibly work as [...] is not valid SQL syntax. Post the actual query. You can replace table names and column names and such with example names, if/where necessary.

2. Show the actual error message instead of some interpretation; the actual message would have mentioned the name of the column that doesn't exist. That would have been useful info.

3. Don't concatenate values into a dynamic query, use USING instead so that the values get properly escaped and don't open you up for SQL injection issues.

The problem you ran into was possibly (we really can't tell from the info you provided) an error in how you quote the various parts of the query, or one of your variables/parameters had a value that contained a quote.

--
If you can't see the forest for the trees,
Cut the trees and you'll see there is no forest.