agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: David G Johnston <david.g.johnston@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: Why data returned inside parentheses in for loop
Date: Mon, 29 Sep 2014 12:34:46 -0700 (PDT)
Message-ID: <1412019286556-5820984.post@n5.nabble.com> (raw)
In-Reply-To: <1412018553142-5820980.post@n5.nabble.com>
References: <1412018553142-5820980.post@n5.nabble.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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-tp5820980p5...
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



view thread (3+ messages)  latest in thread

Message-ID: <1412019286556-5820984.post@n5.nabble.com>
Permalink:  ../1412019286556-5820984.post@n5.nabble.com/
Also on:    postgresql.org/message-id/1412019286556-5820984.post@n5.nabble.com

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: david.g.johnston@gmail.com
  Subject: Re: Why data returned inside parentheses in for loop
  In-Reply-To: <1412019286556-5820984.post@n5.nabble.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox