Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fFoAJ-00031k-1I for pgsql-general@arkaria.postgresql.org; Mon, 07 May 2018 21:59:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fFoAH-0007xi-Ms for pgsql-general@arkaria.postgresql.org; Mon, 07 May 2018 21:59:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fFoAH-0007xY-En for pgsql-general@lists.postgresql.org; Mon, 07 May 2018 21:59:25 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fFoA3-0006P9-Bn for pgsql-general@postgresql.org; Mon, 07 May 2018 21:59:24 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w47Lx6Dn011565; Mon, 7 May 2018 17:59:07 -0400 From: Tom Lane To: "=?ISO-8859-1?B?YQ==?=" <372660931@qq.com> cc: "=?ISO-8859-1?B?cGdzcWwtZ2VuZXJhbA==?=" Subject: Re: How to manipulate tuples in C functions? In-reply-to: References: Comments: In-reply-to "=?ISO-8859-1?B?YQ==?=" <372660931@qq.com> message dated "Tue, 08 May 2018 04:20:16 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <11563.1525730346.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 07 May 2018 17:59:06 -0400 Message-ID: <11564.1525730346@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk "=3D?ISO-8859-1?B?YQ=3D=3D?=3D" <372660931@qq.com> writes: > As far as I know, composite type and rows (trigger functions) are passed= between PostgreSQL and C functions as tuple. However, I rarely find thing= s relating on how to manipulate a tuple under C from documentation. = A lot of low-level stuff like that is only really documented in the server source code. You shouldn't hesitate to look around in the server source and crib from functions that do something related to what you want. > So if anyone can tell me how to answer the above question? Or simply giv= e an example of iterator that go through all entries of a tuple? Thank you= so much!! I'd suggest record_out() in src/backend/utils/adt/rowtypes.c as a prototypical example of disassembling an arbitrary tuple passed as a composite-type argument. (Note that the environment for trigger functions is a bit different, mostly for historical reasons.) regards, tom lane