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 1tmwDZ-000NyM-L9 for pgsql-general@arkaria.postgresql.org; Tue, 25 Feb 2025 14:47:30 +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 1tmwDX-003B9n-Uk for pgsql-general@arkaria.postgresql.org; Tue, 25 Feb 2025 14:47:27 +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 1tmwDX-003B9f-Id for pgsql-general@lists.postgresql.org; Tue, 25 Feb 2025 14:47:27 +0000 Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tmwDU-0000zx-25 for pgsql-general@lists.postgresql.org; Tue, 25 Feb 2025 14:47:26 +0000 Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-5e058ca6806so10235212a12.3 for ; Tue, 25 Feb 2025 06:47:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1740494844; x=1741099644; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=Azya3hV+R/dk5T7PoZxmKUgMYPBtwZOZDDrAIIlL3qs=; b=AxCS3QCZyV/bVproGphzzycf14KgbgNNdwTjtrTamUSvi6ddYT/MS06m39AujVyFfY HGk/yjft6jaCPSJXcNynipX69krkv4abksDiGCDV7N9oQiCnAw+hDD+bdKASD4Jc025S 3j+MdN+8vcrUlP3jl5M0j48YLgoffsdjTeX3ffENVbx99oTJuhOkySu6hrOZh7pU8sW7 GjAazub4AAQKsoB4VvHrjvcuZKoqbP+znJq2OX4u/UGJ2bjccRabSMPviG8l1QlSDZZu fUcPbNzM9xvQChhKz3hvqQXjS5H9hpPd/fKu83DEZasy14Jes5WPxLGuioTcHecqZGqo K13Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740494844; x=1741099644; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Azya3hV+R/dk5T7PoZxmKUgMYPBtwZOZDDrAIIlL3qs=; b=HHYro/zritz58oItkRyGkqeP+tEVnullXIpkFVzf0mNw6DGv0gC9VKbjFgnI9eaK0Z NtkTUrUDsBq4tUaYfjn2suneYRAiHg+X6jQQQJAFiK+ji7YfFUO9+xPBsayA288/3mYe ksFBILezhiSIm6OnikN7az68qiFVd79ql0nmDW0kuk/6KSXv00IMp2AGCS2LCXl0dag3 PC+W9fe89DmXuP4GyBx6TmCZb6vQKVqe/iA0Ebi4PXLZI1fBo0yyuXnu3GABshXA+HDb 9kcWNcjhxh5z9VX7VR0q/54zXM9lrm8XEi4A4pWOSCswEg9zmKOQuq03D72pSHwTyIIY L+uQ== X-Forwarded-Encrypted: i=1; AJvYcCVsftGFLFYgWXkjFMI8No5FTZ2qIIM1q3jkXwz5UoQW9d4yeVJlNjzf04bKgJ1IXLMPyJDjWGF1KMgmhDbV@lists.postgresql.org X-Gm-Message-State: AOJu0Yx1DGqrxOA47hRJLWi9Q1kdBmjTCVoOSfH7XVvR5Yut39cIuiP9 oUIK8+inQfW7tRe/lfgqwcXEzBJDGPjrizOP9dHySP/kK19R2PSohLDiaWjhy8ZlQ7E5MFFDMiQ k X-Gm-Gg: ASbGnctjx8ho228GOXAUkZ7NyZChoSJrsawjI4Re3FGSACIiq8XXa8ViI1/3WCYGI2O gZMRCF18apmic/+cZdDD7YJTD528jxnEAkx2A63BKhkIXyi5aDamMEC1PbHu0MixoSn67wi/Ovf NTDgPqm4JdaaHnUg9T9q/gfD4VnL3SVowBRvHs/jQB70dqm8t3OOQfsV8we6ICEGBp9wYie46V+ hF27gaMvxiNKwARyfoeGtIdLaHnlEOzqklKEIVOHnCfl2svRcxlOWcbbrA3MyMxATBJMUnu4cMA 13NnlGSEI9vjsCRQbYh+AV/oSnYPWoNP4mGOukcoASxY/g== X-Google-Smtp-Source: AGHT+IEJGl/0sXeztWxQlN5vXduOu1NOFIOTdOfMGyRaM/eAo3mFqQpb8BcZOs2H/W3EeyGn5v/krw== X-Received: by 2002:a05:6402:274e:b0:5e0:685f:30b8 with SMTP id 4fb4d7f45d1cf-5e0b724490fmr17557734a12.25.1740494844195; Tue, 25 Feb 2025 06:47:24 -0800 (PST) Received: from localhost.localdomain ([2001:871:5e:ba20:cac9:14ed:5a64:4ac5]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5e496f75f92sm549878a12.28.2025.02.25.06.47.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 06:47:23 -0800 (PST) Message-ID: Subject: Re: How to return seto records from seof record function? From: Laurenz Albe To: =?UTF-8?Q?=D0=9E=D0=BB=D0=B5=D0=B3_?= =?UTF-8?Q?=D0=A1=D0=B0=D0=BC=D0=BE=D0=B9=D0=BB=D0=BE=D0=B2?= , "pgsql-general@lists.postgresql.org" Date: Tue, 25 Feb 2025 15:47:23 +0100 In-Reply-To: <56861740492680@mail.yandex.ru> References: <56861740492680@mail.yandex.ru> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.54.3 (3.54.3-1.fc41) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 2025-02-25 at 17:15 +0300, =D0=9E=D0=BB=D0=B5=D0=B3 =D0=A1=D0=B0=D0= =BC=D0=BE=D0=B9=D0=BB=D0=BE=D0=B2 wrote: > Postgresql 17.2 >=20 > How to return seto records from seof record function? I tried pg_backgrou= nd extension: > =C2=A0 > CREATE OR REPLACE FUNCTION public.autonomous (p_script text) > RETURNS SETOF record > LANGUAGE plpgsql > VOLATILE STRICT PARALLEL UNSAFE > AS $autonomous$ > DECLARE > l_id integer; > BEGIN > l_id :=3D pg_background_launch(p_script); > RETURN QUERY SELECT * FROM pg_background_result(l_id) AS (r record); > END; > $autonomous$; > =C2=A0 > SELECT * FROM autonomous('SELECT now()') AS (a timestamptz); > =C2=A0 > SQL Error [42804]: ERROR: structure of query does not match function resu= lt type > =C2=A0 Detail: Returned type record does not match expected type timestam= p with time zone in column 1. > =C2=A0 Where: SQL statement "SELECT * FROM pg_background_result(l_id) AS = (r record)" > PL/pgSQL function autonomous(text) line 6 at RETURN QUERY You need to be specific: SELECT * FROM pg_background_result(l_id) AS (col1 integer, col2 text, ...= ); I don't think there is a way to get a generic "record" as result. And even if you could, you would still have to specify a column list when you call autonomous(). Attempts to write functions with polymorphic return type are usually futile= . Perhaps you can return a "SETOF jsonb"... Yours, Laurenz Albe