From: | David Johnston <polobo(at)yahoo(dot)com> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | Re: unable to assign value to variable in plpgsql |
Date: | 2014-02-16 16:34:37 |
Message-ID: | 1392568477022-5792296.post@n5.nabble.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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.
From | Date | Subject | |
---|---|---|---|
Next Message | Chirag Mittal | 2014-02-16 16:51:25 | Re: unable to assign value to variable in plpgsql |
Previous Message | Martin Steer | 2014-02-16 16:25:10 | Re: unable to assign value to variable in plpgsql |