Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T9cbF-0003D0-PP for pgsql-sql@postgresql.org; Thu, 06 Sep 2012 13:58:29 +0000 Received: from smtp103.prem.mail.ac4.yahoo.com ([76.13.13.42]) by magus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1T9cbC-0005FG-4L for pgsql-sql@postgresql.org; Thu, 06 Sep 2012 13:58:29 +0000 Received: (qmail 84416 invoked from network); 6 Sep 2012 13:58:22 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=DKIM-Signature:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:Cc:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer:Thread-Index:Content-Language; b=0CNfy06m1FRxIdUV6nObzv9byqndg2L3EGW3AsRIJPZrF3WyMWJ324IdYmtTKELjhTCnsTQORZm2xBDhZE1AJpLV5AufOjPtM9W+/CWY9s9oHWiL94kYJLBwA8ujcjI88/TJEHz9+IEkbW90P9JlwCzFyE3kkguKQ4Ltz94bz0E= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1346939902; bh=O9xQOSe+IBaVwGI4WyDgC/gxSUv1ViSIs0sd1PR7I6g=; h=X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:Cc:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer:Thread-Index:Content-Language; b=rvRomhonevzlAxOD2QIs4ilNxQq6Mgbk4OJD6oZOwoznqvE/TwQb7l4/pcDn3sINYEffotfw/pjg9rUlhqXClDLIOApT+s3EtQ2f1qR3YmorML4+X2wL+hTtLjzERXNtQQ7hDOYqFEah1yorpPjasl8ot5AabrqKQ6+2jhO789A= X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: ndAxPjoVM1kcxDifbcem9YtrO812CmecArWDNHGP.TekUP7 Cq9KrwtXKBlWf5RWIOOPCxid8dXgwpUk2eBV15Lh2jNw9gfFdq9J8FBDxW3w kdIl8exnbNfJAk86zpocPXItfW117W_VpU4h2221EjYKScTCfexruDFZP.tg wMR1FoJqcm1drpNHqtvU9SjqixPmQ3kkhKfmCtrtUk8KqMniYm6HemLsqRWP rhxj53T4_qt1AfY4.fh99LyIYNetscL2MMs5tFtjhViR5GOImC_QqlST3lvC smIjz5kiwNA8gIx0wIqaJ9LXfzEhrbKYwqu3fK6fT9bPgqwPWlCvUDUroKjB T4.B4pWWn9flwO.ztZe9Vd6ZaLESjcveuF8gbUPnyKsIlsIGra3iMKWBDM6v VJZrp96ZlYa0p5gnBDvNe5Nk5lX3NI7xPhYOw X-Yahoo-SMTP: mpGJl6eswBD2IBufoVEg0Pa8gg-- Received: from WolfDog (polobo@24.93.23.188 with login) by smtp103.prem.mail.ac4.yahoo.com with SMTP; 06 Sep 2012 06:58:22 -0700 PDT From: "David Johnston" To: "'Yelai, Ramkumar IN BLR STS'" , "'Sergey Konoplev'" Cc: References: <13D0F6C9B3073A4999E61CAAD61AE7ECC45265BA99@INBLRK77M2MSX.in002.siemens.net> <13D0F6C9B3073A4999E61CAAD61AE7ECC45271D26B@INBLRK77M2MSX.in002.siemens.net> In-Reply-To: <13D0F6C9B3073A4999E61CAAD61AE7ECC45271D26B@INBLRK77M2MSX.in002.siemens.net> Subject: Re: Need to Iterate the record in plpgsql Date: Thu, 6 Sep 2012 09:58:09 -0400 Message-ID: <00fe01cd8c37$a6dddc20$f4999460$@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQHe00jTyJ2qX2rdL3UG0tA9kWHvqADTxEskAg3ZjG6XQ7cWgA== Content-Language: en-us X-Pg-Spam-Score: -2.0 (--) X-Archive-Number: 201209/12 X-Sequence-Number: 36814 Yelai, The etiquette on this list is to place all replies either in-line (but following the content being quoted) or at the end of the posting. My reply is at the end. =============By: Sergey Konoplev If you do not need information about column types you can use hstore for this purpose. [local]:5432 grayhemp@grayhemp=# select * from r limit 1; a | b | c ---+---+--- 1 | 2 | 3 (1 row) [local]:5432 grayhemp@grayhemp=# select * from each((select hstore(r) from r limit 1)); key | value -----+------- a | 1 b | 2 c | 3 (3 rows) The key and value columns here of the text type. ============================== > > Hi All, > > > > I am facing a issue in Iterating the RECORD. > > > > The problem is, I would like to iterate the RECORD without using sql > > query, but as per the syntax I have to use query as shown below. > > > > FOR target IN query LOOP > > statements > > END LOOP [ label ]; > > > > In my procedure, I have stored one of the procedure output as record, > > which I am later using in another iteration. Below is the example > > > > > > CREATE OR REPLACE FUNCTION test2() > > > > Rec1 RECORD; > > Rec2 RECORD; > > Rec3 RECORD; > > > > SELECT * INTO REC1 FROM test(); > > > > FOR REC2 IN ( select * from test3()) > > LOOP > > FOR REC3 IN REC2 --- this syntax does not allowed by Postgresql > > LOOP > > > > END LOOP > > END LOOP > > > > As per the example, How can I iterate pre stored record. > > > > Please let me know if you have any suggestions. > > > > Thanks & Regards, > > Ramkumar > > This makes no sense to me. Since REC2 is a single record from "test3()" there are no "sub-records" to iterate over. Re-reading the thread what you want to do is now iterate over the columns of the record that is currently in play. The following is theoretical: A starting point for doing what you want would be to create a temporary table from the results of the call to "test3()". CREATE TEMP TABLE test3_table AS ON COMMIT DROP SELECT * FROM test3() Now using hstore you can iterate over the columns and retrieve the name and textual value for each. Save the column name and lookup the corresponding column on "test3_table" to determine the data type associated with the value. I do not know the specific syntax to do this but the information is available in the database. It helps to provide the why behind what you are trying to accomplish and just ask whether some behavior can be accomplished or emulated. David J.