From: | Raghavendra <raghavendra(dot)rao(at)enterprisedb(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | "J(dot)V(dot)" <jvsrvcs(at)gmail(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: varchar for loops possible? |
Date: | 2012-05-19 03:37:03 |
Message-ID: | CA+h6Ahh8FHw=vZ_NiT2OjmWDD87nFWiNx+FoTkkMzumPtUMZuA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
As Tom said, you need to declare tmp_var as per the result set coming from
select distinct (value) column.
I gave a try on it.
create or replace function prn_test() returns void as $$
declare
tmp_var test_table.name%type; ///Test_table with name column
which is varchar(20) in my case
begin
for tmp_var in (select distinct name from test_table)
loop
raise notice 'Give anything here :) ... !!!';
update test_table set name=tmp_var;
end loop;
end;
$$ language plpgsql;
---
Regards,
Raghavendra
EnterpriseDB Corporation
Blog: http://raghavt.blogspot.com/
On Sat, May 19, 2012 at 2:10 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> "J.V." <jvsrvcs(at)gmail(dot)com> writes:
> > for tmp_var in select distinct(value) from mytable where
> > value2='literal'
> > tmp_var has to be in ' ' ticks or will not work. it is failing on the
> > first FOR statment stating: "invalid input syntax for integer:
> > "some_distinct_value".
>
> Um, how do you have tmp_var declared? plpgsql seems to be acting
> as though it's an integer variable, which is not what you need if
> "value" is a varchar.
>
> regards, tom lane
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>
From | Date | Subject | |
---|---|---|---|
Next Message | John Watts | 2012-05-19 11:04:27 | Re: difference in query plan when db is restored |
Previous Message | Bosco Rama | 2012-05-19 00:58:34 | Re: Why are pg_restore taking that long ? |