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 1sEs90-004CBP-4j for pgsql-general@arkaria.postgresql.org; Wed, 05 Jun 2024 15:01:43 +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 1sEs8x-009EPr-Fh for pgsql-general@arkaria.postgresql.org; Wed, 05 Jun 2024 15:01:39 +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 1sEs8w-009EPj-2M for pgsql-general@lists.postgresql.org; Wed, 05 Jun 2024 15:01:39 +0000 Received: from fhigh8-smtp.messagingengine.com ([103.168.172.159]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sEs8s-003atp-Q7 for pgsql-general@postgresql.org; Wed, 05 Jun 2024 15:01:36 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 7C7FD1140116; Wed, 5 Jun 2024 11:01:32 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 05 Jun 2024 11:01:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1717599692; x=1717686092; bh=PAJAWXaSmToX+1oQSX1TWA8if5K+H/hMqXMGtBss8zo=; b= lDEz9K4ZDScqzyg8zaqmaGOqLu674a7N8yZt21zYEmYPdGj9fq7UdawkH7VauzBj pP7QD3MW77H2nL99c2+RxsbifjkErZ9ITReyAniYDGTxQN7LDVxZV2atuJWSfAoP 5W9zf+9xWgmk8oaurvwkfPZU2I6a1A0FcgD6T3iXEnjdk1fahsp4ZMfXHqDrTnxE RppLufywV+r4c9DCMGa9l+2wsxvgNBlveTt6kZhW+lcN0n46Hh4Be+hdZiwMnb+o lG2sNxvXM02dtANXFOB2xCa4m15IPEfTRo7bJfx7/1ayj4IwjAcGy2k8sPTtrBBF a9ZEgrmQj3XsiATNaEIa3A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1717599692; x= 1717686092; bh=PAJAWXaSmToX+1oQSX1TWA8if5K+H/hMqXMGtBss8zo=; b=h tJWmNsLWpsa0c/BcCZOns3rSrP7WUlkg5dT5Oi9vfRcrtgY5tEvUYWaGuHRU45Fa uNExjI3H4MDqOsCz1lwTAn+M/wzWAwgD2ffhFQACrx43QyljPmHTN8eiTFIHpO6C 0mPszC8L+RM8TULdCnQmHcpG50DBViH3Ax/4Xhrm0VPLXw96FtXDowMV5IQCIDrn NHy4AckdMs3BCyPQILXiUjmQc5YTgpYrd4DWGwFTTCFqdvgesCecaAazzWcEA2yk s1ADlnZZupBwnHA5akX/IFHUCDE8h9s1iujtTdy46XwlNA2hnGpZIdJ5VdKelR2m gubc/Wp4d+NW3A5cJWukw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeliedgkeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvfhfhjggtgfesthekredttddvjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeelgeevkeekkeeuiefgtdevieeluefhfedufeetkeej ffekjeeujeehgeehgeektdenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhi rghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 5 Jun 2024 11:01:31 -0400 (EDT) Message-ID: Date: Wed, 5 Jun 2024 08:01:30 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Variant (Untyped) parameter for function/procedure To: Durumdara , Postgres General References: Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 6/5/24 01:34, Durumdara wrote: > Dear Members! > > As I experienced, the functions/procedures extremely depend on > parameters (very typed). > So if I have to restructure the input parameters, I can't modify the > function, because I have to recreate the dependents too. > For example: > I have a type. If I pass this type to a function, I can't change the > structure of the type without dropping and recreating the function. > > create type blahtype as (a int, b bool); > create function blahcheck (input blahtype) ... > > > If I have many dependent functions this causes that I have to drop > (recreate) everything - just for an extra parameter. And sometimes this > extra parameter doesn't change 10 functions, only one. But I have to > recreate them all (without changing the body). > > Is there any way to use a Variant parameter? You mean like: https://www.postgresql.org/docs/current/extend-type-system.html#EXTEND-TYPES-POLYMORPHIC Examples here: https://www.postgresql.org/docs/current/plpgsql-declarations.html#PLPGSQL-DECLARATION-PARAMETERS Starting at: "... When the return type of a PL/pgSQL function is declared as a polymorphic type ..." Or there is VARIADIC: https://www.postgresql.org/docs/current/xfunc-sql.html#XFUNC-SQL-VARIADIC-FUNCTIONS > Like this: > > create procedure test(IN Input Record, OUT Output Record) > ... >     Time = Input.Time::timestamp; > ... > >     Output = SomeHowMakeItTyped; > >     Output.Result = 1; > > ... > > > Caller: > > ... > for r_in as select  id, name from blah into > ... >      test(r_in, r_out); >      if r_out.result <> 0 then ... > > Or: > > create procedure test(IN Inputs Records, OUT Output Record) > ... >         for Input in Inputs: >         Time = Input.Time::timestamp; > ... >     Output.Result = 1; > ... > > > > > Or is it impossible, because of the PGSQL's philosophy (very typed)? > > If it is not possible then I have one way I think. > It is a JSON data type for inputs and outputs. > > Is that right? > > Thanks for your any help, info! > > Best regards > dd > > > > > -- Adrian Klaver adrian.klaver@aklaver.com