Re: Why data returned inside parentheses in for loop

Поиск
Список
Период
Сортировка
От David G Johnston
Тема Re: Why data returned inside parentheses in for loop
Дата
Msg-id 1412019286556-5820984.post@n5.nabble.com
обсуждение исходный текст
Список 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.



В списке pgsql-sql по дате отправления:

Предыдущее
От: Pavel Stehule
Дата:
Сообщение: Re: how to see "where" SQL is better than PLPGSQL
Следующее
От: David G Johnston
Дата:
Сообщение: Re: Why data returned inside parentheses in for loop