Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o7D9n-0001zB-3P for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Jul 2022 09:41:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1o7D9l-00019n-Su for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Jul 2022 09:41:45 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o7D9l-00019e-JE for pgsql-hackers@lists.postgresql.org; Fri, 01 Jul 2022 09:41:45 +0000 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o7D9j-0002Wn-6E for pgsql-hackers@postgresql.org; Fri, 01 Jul 2022 09:41:44 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 2481E3200957; Fri, 1 Jul 2022 05:41:41 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Fri, 01 Jul 2022 05:41:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1656668500; x= 1656754900; bh=bQPlaf3ngMfDsqaG1w7/BEItrgfnQDxzL610ke4uI70=; b=D JbeomGSmPjX/6q5iAWfVoOX/5vbgX44eCX6hn42ZN9zUnZ6kohtVPRDWHUxTEdd2 npHhqm/7F+MH9rD0evwOcvo1wc8afnfoFC08utMSza9PwfuYo2pxMnpfybTGOak8 DLpOqPW6ZNX6Gih3uM78JUI5E+UGZmVqshYThNZKUh/l9mgIbkrCSQjd7JWjcl8i ojVsjgR23doBJGWkCtTDdZuSEJ6UsB2zAsveHD/xOXr9/hVMjb+adgDpkrvEIjsV 06nyKxhjRiv8uc8iXZDhffZbELf6uEzDXPxDN4uJyZ146KJsJCzbxxOMZn97wUuY /a/QWJfl4sfDrQuCeX2hg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrudehfedgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefkffggfgfuvfevfhfhjggtgfesth ejredttdefjeenucfhrhhomheprfgvthgvrhcugfhishgvnhhtrhgruhhtuceophgvthgv rhdrvghishgvnhhtrhgruhhtsegvnhhtvghrphhrihhsvggusgdrtghomheqnecuggftrf grthhtvghrnhepheelffeggedujeetiefhleetuddvieffhfffvdejvdffgeejkeduledu heduieefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh epphgvthgvrhdrvghishgvnhhtrhgruhhtsegvnhhtvghrphhrihhsvggusgdrtghomh X-ME-Proxy: Feedback-ID: i131946ab:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 1 Jul 2022 05:41:39 -0400 (EDT) Message-ID: Date: Fri, 1 Jul 2022 11:41:37 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: Refactor construct_array() and deconstruct_array() for built-in types Content-Language: en-US To: Tom Lane Cc: pgsql-hackers References: <2914356f-9e5f-8c59-2995-5997fc48bcba@enterprisedb.com> <1844517.1651502932@sss.pgh.pa.us> From: Peter Eisentraut In-Reply-To: <1844517.1651502932@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 02.05.22 16:48, Tom Lane wrote: > Peter Eisentraut writes: >> There are many calls to construct_array() and deconstruct_array() for >> built-in types, for example, when dealing with system catalog columns. >> These all hardcode the type attributes necessary to pass to these functions. > >> To simplify this a bit, add construct_array_builtin(), >> deconstruct_array_builtin() as wrappers that centralize this hardcoded >> knowledge. This simplifies many call sites and reduces the amount of >> hardcoded stuff that is spread around. > >> I also considered having genbki.pl generate lookup tables for these >> hardcoded values, similar to schemapg.h, but that ultimately seemed >> excessive. > > +1 --- the added overhead of the switch statements is probably a > reasonable price to pay for the notational simplification and > bug-proofing. > > One minor coding gripe is that compilers that don't know that elog(ERROR) > doesn't return will certainly generate "use of possibly-uninitialized > variable" complaints. Suggest inserting "return NULL;" or similar into > the default: cases. I'd also use more specific error wording to help > people find where they need to add code when they make use of a new type; > maybe like "type %u not supported by construct_array_builtin". I have pushed this with the improvements you had suggested.