Re: unable to assign value to variable in plpgsql

Поиск
Список
Период
Сортировка
От David Johnston
Тема Re: unable to assign value to variable in plpgsql
Дата
Msg-id 1392568477022-5792296.post@n5.nabble.com
обсуждение исходный текст
Ответ на unable to assign value to variable in plpgsql  (Chirag Mittal <linux@seasonstravel.co.in>)
Ответы Re: unable to assign value to variable in plpgsql  (Chirag Mittal <linux@seasonstravel.co.in>)
Список pgsql-novice
Chirag Mittal wrote
> Hi,
>
> I am trying to assign number of row as integer
>
> Tried 1
> maz int :=(SELECT count(col1) FROM table WHERE col1 = quote_literal(in
> val1));

Use of quote_literal is pointless.
Prefixing variable name with in is wrong.  In/out are only used in function
declarations.  While not explicitly documented all of the examples that use
input variables show the proper usage.
Specifying a type after a variable name is ok if you doing this in the
declare section, I think.  Usually easier to relegate all queries to the
main body in which case the type specifier is wrong.


> Tried 2
>
> EXECUTE 'SELECT count(col1) FROM table WHERE col1 = quote_literal(val1)
> INTO maz';
> getting error INTO
>
> Regards
> Chirag

INTO belongs outside of the command string.
Instead of quote_literal you would usually want to use a parameter here for
val1 and add a USING clause.

Have you read the documentation for pl/pgsql? It is quite thorough and even
has section headers that nearly match your question so that learning how to
do this should be easy to find.

David J.



--
View this message in context:
http://postgresql.1045698.n5.nabble.com/unable-to-assign-value-to-variable-in-plpgsql-tp5792281p5792296.html
Sent from the PostgreSQL - novice mailing list archive at Nabble.com.


В списке pgsql-novice по дате отправления:

Предыдущее
От: Martin Steer
Дата:
Сообщение: Re: unable to assign value to variable in plpgsql
Следующее
От: David Johnston
Дата:
Сообщение: Re: unable to assign value to variable in plpgsql