Re: unable to assign value to variable in plpgsql

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:51:47
Message-ID: 1392569507299-5792299.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Martin Steer wrote
> On Sun, Feb 16, 2014 at 04:22:28AM -0800, 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)); Tried 2
EXECUTE
>>'SELECT count(col1) FROM table WHERE col1 = quote_literal(val1) INTO maz';
>>getting error INTO Regards Chirag
>
> select count(*)
> into maz
> from tablename
> where col1 = 'val1';
>
> maz int := count(*) from tablename where col1 = 'val1';
>
> M.

Note that if val1 is a variable you do not use quotes. Only when it is a
literal/constant. Using quotes makes it into a literal/constant.

David J.

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

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Andrew Puschak 2014-02-17 14:36:57 Re: Access 2003 reports queries taking very long
Previous Message Chirag Mittal 2014-02-16 16:51:25 Re: unable to assign value to variable in plpgsql