Re: Why data returned inside parentheses in for loop

From: David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Why data returned inside parentheses in for loop
Date: 2014-09-29 19:34:46
Message-ID: 1412019286556-5820984.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

wujee wrote
> Dear all,
>
> I have a simple query but the data returns inside parentheses, I think
> there may be parameters that control this behavior but not sure what it
> is.
>
> This is what I Have:
> begin
> for i in (select salary from salaries where employee_id > 1001) loop
> dbms_output.put_line('i value: '||i);
> end loop;
> end;
>
>
> And I got the result as the followings:
> i value: (375402)
> i value: (37539)
> i value: (375394)
>
>
> I do not want "(" and ")" in between the values, how should I do that?
>
>
> Thanks,
> Tina

dbms_output.put_line('i value: ' || i.salary)

"i" is a record type that has a single "salary" column. If it had two
columns, say "SELECT name, salary FROM ..." you would have gotten (correct
quoting not withstanding):

i value: ('Name', 375402)

pl/pgsql does not automatically reduce a single column to be a simple scalar
- the "for rec_var in (query)" always results in rec_var being of type
"record".

David J.

--
View this message in context: http://postgresql.1045698.n5.nabble.com/Why-data-returned-inside-parentheses-in-for-loop-tp5820980p5820984.html
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message David G Johnston 2014-09-29 21:16:45 Re: Why data returned inside parentheses in for loop
Previous Message Pavel Stehule 2014-09-28 19:44:32 Re: how to see "where" SQL is better than PLPGSQL