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 1nlXM9-0000pO-GR for pgsql-hackers@arkaria.postgresql.org; Mon, 02 May 2022 14:48:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nlXM8-0002J4-Bl for pgsql-hackers@arkaria.postgresql.org; Mon, 02 May 2022 14:48:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nlXM8-0002Iv-2l for pgsql-hackers@lists.postgresql.org; Mon, 02 May 2022 14:48:56 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nlXM6-000846-NF for pgsql-hackers@postgresql.org; Mon, 02 May 2022 14:48:55 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 242EmqPR1844518; Mon, 2 May 2022 10:48:52 -0400 From: Tom Lane To: Peter Eisentraut cc: pgsql-hackers Subject: Re: Refactor construct_array() and deconstruct_array() for built-in types In-reply-to: <2914356f-9e5f-8c59-2995-5997fc48bcba@enterprisedb.com> References: <2914356f-9e5f-8c59-2995-5997fc48bcba@enterprisedb.com> Comments: In-reply-to Peter Eisentraut message dated "Mon, 02 May 2022 10:38:59 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1844516.1651502932.1@sss.pgh.pa.us> Date: Mon, 02 May 2022 10:48:52 -0400 Message-ID: <1844517.1651502932@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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". regards, tom lane