Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sJyWH-007ee7-OC for pgsql-general@arkaria.postgresql.org; Wed, 19 Jun 2024 16:50:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sJyWF-002cnu-EN for pgsql-general@arkaria.postgresql.org; Wed, 19 Jun 2024 16:50:48 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sJyWF-002cnm-3P for pgsql-general@lists.postgresql.org; Wed, 19 Jun 2024 16:50:47 +0000 Received: from mail-oa1-x32.google.com ([2001:4860:4864:20::32]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sJyWD-0026mR-Dt for pgsql-general@lists.postgresql.org; Wed, 19 Jun 2024 16:50:46 +0000 Received: by mail-oa1-x32.google.com with SMTP id 586e51a60fabf-24c9f6338a4so28488fac.1 for ; Wed, 19 Jun 2024 09:50:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718815844; x=1719420644; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=JKLg8uI8pDpnC4qB2P9TWPVF/U6f8GTeRkwO2Wve6Yc=; b=S+okoIVB8txuDHlk7P9EtaHQiUSh9lySt9TLbjhVNG6XzAhxzdqsr4F0dJ5697MQqx 1s+hOZn6bGfAEiRj9v9ENsCQNzj1XITk5zrVDj2mr8GbCeWrdrRDfmZxFSpVo/dFKaIH 2MlheE67Y/kw/eGorHPHKlw1FPJmrBbfHRbGrc8NNOUx3W+Hl2aLvKwxEbbb9oB42Yls ZQf5qL549Dz6UTUhUP9D1mimO5yCdCcONupxM30JbFah0LAiWbRpuNkGevnLz9kay47e 08NXHXbGOlRtdEzRrrIlI1FwjxPjeE3xHH9yxMs4Ll7EqUyhAixHV2Xg6uC+szRU/HxU Mbnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718815844; x=1719420644; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JKLg8uI8pDpnC4qB2P9TWPVF/U6f8GTeRkwO2Wve6Yc=; b=lwMchoibut77vE7Y4+l8tkK2Gt94Xu/KSmYOcsdteU2t/KLsCZb3b9IXPoFNo/EEhc 5hp6gFlcPIbmP3B8v4HqBtYkrPGFYHsFEko8fSgkAIVEewvgBFTT6NPt2MnMKRBjFFbU Rtx1R+aeISzUmKmYZJgYrJRivyU5EoqxVIeKfTk8dBqPxn76Jny+tTDNXr4lv1dD3YvQ svXSNx0ht8O9bh0F2StqIRyDG3lFcd+GSuFXIfDRHWKBQnQnnvZdXyf/Eza/E5eSR1WQ RDWOe0Ef7CTvBIAV19RskkAAqGR0p4jT8CrANdtnL4NUWDpYXJfqWaimnMvBvxQ8uKtZ pXzA== X-Gm-Message-State: AOJu0YxZ2YzkPgNeAAj56veUTYjDn1C7bR1OuQa/fMwdKY0FKP4sG3Lj 6toA3gCu2rCY+DVdLsFY9QfgJNyZr8lZ+0IMyggvLZOiscN1kzEqRO3g/ne2S/m5Qw8+CboiE5F WuPURTA2nlxVhLETGgfdX9qZ5kqogUg== X-Google-Smtp-Source: AGHT+IGVZ5DRU0HgvEKX39DRtIT5Az0UXB+5+erAnkAy8h7gvUT3EMz3sG21MfN9Wf+P+nh6qtURYBn+Hfdsizs2jeE= X-Received: by 2002:a05:6870:71c1:b0:259:8b4e:e71a with SMTP id 586e51a60fabf-25c94d07918mr3614396fac.46.1718815844625; Wed, 19 Jun 2024 09:50:44 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:ac9:77c6:0:b0:530:392d:d678 with HTTP; Wed, 19 Jun 2024 09:50:44 -0700 (PDT) In-Reply-To: References: From: "David G. Johnston" Date: Wed, 19 Jun 2024 09:50:44 -0700 Message-ID: Subject: Re: Seeking Clarification on Function Definitions in PostgreSQL Extensions To: Ayush Vatsa Cc: "pgsql-general@lists.postgresql.org" Content-Type: multipart/alternative; boundary="000000000000da7528061b40ff74" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000da7528061b40ff74 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wednesday, June 19, 2024, Ayush Vatsa wrote: > Hi David, > Thanks for clarification > > I prefer TABLE. Using setof is more useful when the returned type is > predefined > But in the table also isn't the returned type predefined? Example: > CREATE FUNCTION fun1(integer) > RETURNS TABLE( > col1 integer, > col2 text > ) > AS 'MODULE_PATHNAME', 'fun1' > LANGUAGE C; > We know the returned type will have two columns with type - integer and > text. Am I correct? > Sorry, predefined independently of the function. Using create type then referring to that type by name in the create function. > > > Or a true record where the caller has to specify the shape. > Sorry but didn't get this shape part? > =E2=80=A6 from rec_func as (col1 isn=E2=80=99t, col2 text) =E2=80=A6 The shape is two columns, type int and text respectively. David J. --000000000000da7528061b40ff74 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wednesday, June 19, 2024, Ayush Vatsa <ayushvatsa1810@gmail.com> wrote:
Hi David,
Thanks for cla= rification
>=C2=A0I prefer TABLE.=C2=A0 Using setof is more useful when the returned type= =C2=A0is predefined
But in the table also isn't the returned type pr= edefined? Example:
CREATE FUNCTION fun1(intege= r)
RETURNS TABLE(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 col1 integer,
=C2=A0= =C2=A0 =C2=A0 =C2=A0 col2 text
)
AS 'MODULE_PATHNAME', '= fun1'
LANGUAGE C;
We know the returned type will have = two columns with type -=C2=A0 integer and text. Am=C2=A0I correct?

Sorry, predefined independently of the = function.=C2=A0 Using create type then referring to that type by name in th= e create function.
=C2=A0

>=C2=A0Or a true record where the caller has to specify th= e shape.
Sorry but didn't get this shape part?

=E2=80=A6 from rec_func as (col1 i= sn=E2=80=99t, col2 text) =E2=80=A6

The shape is tw= o columns, type int and text respectively.

David J= .

--000000000000da7528061b40ff74--