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 1fJ2a2-0003oX-Mg for pgsql-general@arkaria.postgresql.org; Wed, 16 May 2018 19:59:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fJ2a1-0008N8-C8 for pgsql-general@arkaria.postgresql.org; Wed, 16 May 2018 19:59:21 +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 1fJ2a0-0008My-BK for pgsql-general@lists.postgresql.org; Wed, 16 May 2018 19:59:21 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fJ2Zu-0001aB-JI for pgsql-general@postgresql.org; Wed, 16 May 2018 19:59:19 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 0C9592219E; Wed, 16 May 2018 15:59:13 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 16 May 2018 15:59:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=dzvrHNYRu3yVLVq2n8vnZPJ1GNNUl +wPJKqzVjuRcZA=; b=g3vkm5aDv4PPaV7eg8ZGIYW4f1duS5qBTXZPBDaMJSggk cOYnBXlMQOQmF7GYIk6cNuc3aDRus0oIQkR7n3TWDAArP2CQDb4QmYVbBgtMCDZk N7CuLo9VeO8CW5hDy0Ags+jVp+mZ4x7AxRqwDhDPND6Nksk7eL0m72RYONKShIal Awl4cf29cvSbUw/iNnnW+WHb5a8XzgfcoT7Wthg6COSJupe1A4KfM+b/1qWE3j7S yRrGhxcXITQo6+PTQpDKLHx5taSeiL0u+xs464RzN5PovHrDA3U0V4ITDqQn7vk6 DqD4hotKafqQ8r2CgjCUydfs69Wjwvgu0EYsRzhtw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=dzvrHN YRu3yVLVq2n8vnZPJ1GNNUl+wPJKqzVjuRcZA=; b=KTCnZeUif0yZfQcs8yAO01 ljVd4RDZh7x4oepi93KxIeN6ae5d7qHLvpXCejujRkwq5oZkYL9AMkFy0MtYSz3O pmz1tq1MXh1TRsAo9j6FnahNP0f6Q89RE+S2NXtJwDP/AmeCd8XsiHQSeqMKKn+V sio6BpFusXaJM+4E8Hxsu40U9durSQRzSaiQYzW8saUcrfoz6j9ZgOAMl2vPUsPp yWIFjk8tT7u44Ss9agZoazz3PsGde1ZyWsQrePCWhG5SOUcJzlrjwc8tlBaDJ6hS o+k4Zet+uH0gjNWyuR4D92cr+sJCKYaRPteSatW+/i/cJmTDJEi8IqTqJ6BCcMJw == X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Sender: Received: from [192.168.1.2] (unknown [71.212.135.74]) by mail.messagingengine.com (Postfix) with ESMTPA id 47D39E498C; Wed, 16 May 2018 15:59:12 -0400 (EDT) Subject: Re: sql function with empty row To: Philipp Kraus Cc: "pgsql-general@postgresql.org" References: <72B01876-DA02-4306-9994-F7F1F12A7C29@tu-clausthal.de> From: Adrian Klaver Message-ID: <6dc24153-7c52-4bcd-1b2b-5ff31a1f3fec@aklaver.com> Date: Wed, 16 May 2018 12:59:11 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <72B01876-DA02-4306-9994-F7F1F12A7C29@tu-clausthal.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 05/16/2018 11:49 AM, Philipp Kraus wrote: > >> Am 16.05.2018 um 20:40 schrieb Adrian Klaver : >> > > I have tested it on my data and it works also, but that is a little bit confusing, because imho setof is >= 0 rows and > without setof it is [0,1]. On this I know there exist only one or no record, so I choose the solution without setof I gotta believe the difference is: RETURNS substance https://www.postgresql.org/docs/10/static/xfunc-sql.html#XFUNC-SQL-TABLE-FUNCTIONS " If the function is defined to return a composite type, the table function produces a column for each attribute of the composite type." RETURNS SETOF substance https://www.postgresql.org/docs/10/static/xfunc-sql.html#XFUNC-SQL-FUNCTIONS-RETURNING-SET "When an SQL function is declared as returning SETOF sometype, the function's final query is executed to completion, and each row it outputs is returned as an element of the result set." > > Thanks for help > > Phil > -- Adrian Klaver adrian.klaver@aklaver.com