[GENERAL] varchar for loops possible?

2012-05-18 Thread J.V.
I have a table with a varchar column. I want to select the distinct values from this column and loop through them (using as a variable) in a raise notice statement and also in an update statement. I have not been able to do this trying over 100 things in the last two hours. I could not find

Re: [GENERAL] varchar for loops possible?

2012-05-18 Thread Tom Lane
"J.V." 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 dec

Re: [GENERAL] varchar for loops possible?

2012-05-18 Thread Raghavendra
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 b

Re: [GENERAL] varchar for loops possible?

2012-05-21 Thread Jasen Betts
On 2012-05-18, J.V. wrote: > I have a table with a varchar column. > > I want to select the distinct values from this column and loop through > them (using as a variable) in a raise notice statement and also in an > update statement. > > I have not been able to do this trying over 100 things in

Re: [GENERAL] varchar for loops possible?

2012-05-21 Thread Raymond O'Donnell
On 18/05/2012 21:30, J.V. wrote: > update table set varcharid = ''' || tmp_var || ''' Others have answered your question, but there's a problem here too; you don't need the quotes. This statement should be just: update table set varcharid = tmp_var; ...assuming that the types match, of course.