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.96) (envelope-from ) id 1wbtta-002vqc-2x for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Jun 2026 05:42:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wbttZ-009jMd-2W for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Jun 2026 05:42:01 +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.96) (envelope-from ) id 1wbttY-009jMU-2G for pgsql-hackers@lists.postgresql.org; Tue, 23 Jun 2026 05:42:01 +0000 Received: from mail.clear-code.com ([153.126.203.179]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wbttW-00000001hI3-1xLc for pgsql-hackers@postgresql.org; Tue, 23 Jun 2026 05:41:59 +0000 Received: from localhost (unknown [IPv6:2404:7a80:9f01:f500:1788:74de:dc85:ea72]) by mail.clear-code.com (Postfix) with ESMTPSA id 07C84120514; Tue, 23 Jun 2026 14:41:51 +0900 (JST) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.clear-code.com 07C84120514 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=clear-code.com; s=default; t=1782193312; bh=uoMi88txIvpEyMZwjmV7ophSpKsso8XfptbHWRPGzGw=; h=Date:To:Cc:Subject:From:In-Reply-To:References:From; b=g1TTkknpTUIPu11AXGHVQVhybxnVyHip4o7X/nez2dcXM/2fye79ieAjSllGvIegk BqXXl6p6iu0hm/IBaA5kzUqJ+Um+b4MDukKK32yOgfvQ47ivi0Te7fcn3Hb3osqqFn cg+gPndFctlCpYBKXFO0t0/MS6tK1mVf/XLL7TO8= Date: Tue, 23 Jun 2026 14:41:49 +0900 (JST) Message-Id: <20260623.144149.439869848255136426.kou@clear-code.com> To: sawada.mshk@gmail.com Cc: tomas@vondra.me, andres@anarazel.de, michael@paquier.xyz, david.g.johnston@gmail.com, tgl@sss.pgh.pa.us, zhjwpku@gmail.com, pgsql-hackers@postgresql.org Subject: Re: Make COPY format extendable: Extract COPY TO format implementations From: Sutou Kouhei In-Reply-To: References: <20260327.103640.1195140797832123502.kou@clear-code.com> X-Mailer: Mew version 6.8 on Emacs 30.2 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 07C84120514 X-Spamd-Result: default: False [2.90 / 999.00]; SUSPICIOUS_RECIPS(1.50)[]; MID_CONTAINS_FROM(1.00)[]; MV_CASE(0.50)[]; MIME_GOOD(-0.10)[text/plain]; ASN(0.00)[asn:2518, ipnet:2404:7a80::/29, country:JP]; ARC_NA(0.00)[]; FREEMAIL_TO(0.00)[gmail.com]; RCPT_COUNT_SEVEN(0.00)[8]; RCVD_COUNT_ZERO(0.00)[0]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; ALIAS_RESOLVED(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_NONE(0.00)[]; LOCAL_OUTBOUND(0.00)[]; FREEMAIL_CC(0.00)[vondra.me,anarazel.de,paquier.xyz,gmail.com,sss.pgh.pa.us,postgresql.org] X-Rspamd-Action: no action X-Rspamd-Server: mail.clear-code.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, Thanks for restarting this. In "Re: Make COPY format extendable: Extract COPY TO format implementations" on Mon, 22 Jun 2026 18:06:07 -0700, Masahiko Sawada wrote: > After more thought, I'd like to keep the custom-format changes to the > bare minimum and not disturb the existing built-in format processing. +1 > Updated patches attached: > > - 0001 moves CopyFromStateData and CopyToStateData to a new > copy_state.h, so extensions can implement their routines without > including the *_internal.h headers. It also drops file_fdw.c's > dependency on copyfrom_internal.h. +1 > - 0002 introduces the registration API and the opaque per-format > pointer in both structs. > --- /dev/null > +++ b/src/backend/commands/copyapi.c > +bool > +GetCopyCustomFormatRoutines(const char *name, const CopyToRoutine **to, > + const CopyFromRoutine **from, ProcessOneOptionFn * option_fn) How about returning CopyCustomFormatEntry instead? The function name is "Get...Routines" but it also returns ProcessOneOptionFn. "Get...Routines" is a bit strange. > --- a/src/include/commands/copyapi.h > +++ b/src/include/commands/copyapi.h > @@ -102,4 +103,40 @@ typedef struct CopyFromRoutine > ... > +typedef bool (*ProcessOneOptionFn) (CopyFormatOptions *opts, bool is_from, > + DefElem *option); How about adding "Copy" keyword to the type name such as "ProcessOneCopyOptionFn" because this is only for COPY format? > --- a/src/include/commands/copy.h > +++ b/src/include/commands/copy.h > @@ -58,7 +58,16 @@ typedef enum CopyFormat > ... > +#define CopyFormatBuiltins(format) ((format) != COPY_FORMAT_CUSTOM) How about renaming this to CopyFormatIsBuiltin() or something? "...Builtins" is a bit strange because this returns a boolean. > - 0003 adds a callback to validate the COPY options as a whole, called > after all options are processed. > --- a/src/include/commands/copyapi.h > +++ b/src/include/commands/copyapi.h > @@ -120,6 +120,15 @@ typedef struct CopyFromRoutine > ... > +typedef void (*ValidateOptionsFn) (CopyFormatOptions *opts, bool is_from); How about adding "Copy" keyword like "ValidateCopyOptionsFn"? > - 0004 adds the regression tests. > --- /dev/null > +++ b/src/test/modules/test_copy_custom_format/test_copy_custom_format.c > @@ -0,0 +1,169 @@ > ... > +TestCopyProcessOneOption(CopyFormatOptions *opts, bool is_from, DefElem *option) > +{ > + TestCopyOptions *t = (TestCopyOptions *) opts->format_private_opts; > + > + if (t == NULL) > + { > + t = palloc0_object(TestCopyOptions); > + opts->format_private_opts = (void *) t; > + } This is not a blocker but we may want to add InitializeCopyOptions callback for this. Thanks, -- kou