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 1uDYYh-00CTMw-Kv for pgsql-hackers@arkaria.postgresql.org; Sat, 10 May 2025 00:59:20 +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 1uDYXg-00GLJO-EK for pgsql-hackers@arkaria.postgresql.org; Sat, 10 May 2025 00:58:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uDYXg-00GLJG-2c for pgsql-hackers@lists.postgresql.org; Sat, 10 May 2025 00:58:16 +0000 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uDYXd-0016yR-09 for pgsql-hackers@postgresql.org; Sat, 10 May 2025 00:58:15 +0000 Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-54e7967cf67so3231762e87.0 for ; Fri, 09 May 2025 17:58:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746838692; x=1747443492; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=01lbKMI1yHVZ6R2TGNJo/IEy5kZVTacea/falyPKAZs=; b=Nd/qi+y+UACNr/oqHSqErbUglaGA+iHSgy+iDWlnTnOe8rt/TD6/pURwlEkkuBbUpd O4Iz6HbVfXErlNquy98TRLsZFmNz20tlf9s2TTQl/yBM4Ilx6QCQ/AzciOLZJHHazpqW FgpTdnJ6dBgggsyEz7eMWp4AZJ00KGgChUrk4Rx5RX6WF4+Vv+cP8GmAS3R+n3L5AlAh 3S4/Hf/k7amzZZXvBhKrH2gPLUg86ODKeT85z9qLUk0N9c4rGbQC3DMNKxY2XzTAYPJ+ cV2mdlNCKjDba8BFdcW1pJ5dX9d0hbdQQsenOg1zdlsugO1Dawj1Lcc97yF6NkXs4xR/ J4Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746838692; x=1747443492; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=01lbKMI1yHVZ6R2TGNJo/IEy5kZVTacea/falyPKAZs=; b=AhGV8YDJrWYexkOV65HFfdryw8ZFiJvRq0olU3aZE0Z0ybbqQFUmUSfhqxAZOxpvob sZs3DiKo8KzmjJdITr3xIJydwp+kT2x2ywSJv2JjU1qDuUpZViVRBgdblQ1+a74+IYA2 6pNWiY75KC7bgXUpgGFs4IKWBcodoAu++kZ1Jj8pej5nc3zqGd0BEeOM00z9jqxiPDeO 5JTHBNbw7x+GWU92Prr6+Is4pkotbNm3KeZ9Erjw6BbUXvZb9m7UAgYdQulJvX/kXzaU HCTBzr015aDpZ/oDsyDg+ctB68DzyIe0OHZDsebqq9QsT3t5qFWVpl9oZtN8J8I0tSdi t7Yw== X-Forwarded-Encrypted: i=1; AJvYcCW56dHXjToyYt+ac1L+ZzQs45RLoyLUxoRcg3ibLPR4OyP8UNYFkIedG+5sZkamv2hjp7BfbXKmU7veZxwj@postgresql.org X-Gm-Message-State: AOJu0Ywsq6jxd1Wmp6WM4vR4rMQuWR3+PVLfT+kZYYZq09c+pssE8xKQ yttXIl0+V+KuLau/uayCkgEKAAQGBHC5S55P8LkhuJ1pNPPGQ0WWXZplMTNg18EykZw9OXqOuJ8 fCOFBMOR9Tdp+CE8cROi83HQ1rDM= X-Gm-Gg: ASbGncstpnJxfMH1E/jVN8WWSy70vecGb37A+wdt4tesw72RRepOYnjzxFA10F5VJfQ 1HGNkI4aQRLOwKrdE1y7nfWwWpX7WzRB3ejZFZPJmdZnirDzMDdBJjArQDySZQZfZ+8qV5f0XxH 0t+G4v1zr99W3HXER3ysaL8BsgpFBHZOtj/WFSr5/pJXnD X-Google-Smtp-Source: AGHT+IE9jEgu4oHg4wYd9EaOmdmoc0b380f8TXUsUhSdGOxXgRlWBC5Twji5Ob4nMtbojW071juQJGtzEkiD/IAZyJc= X-Received: by 2002:a05:6512:450c:b0:54f:ca1c:aea0 with SMTP id 2adb3069b0e04-54fca1caf1emr1051509e87.33.1746838692234; Fri, 09 May 2025 17:58:12 -0700 (PDT) MIME-Version: 1.0 References: <20250509.184137.254173769823586829.kou@clear-code.com> In-Reply-To: <20250509.184137.254173769823586829.kou@clear-code.com> From: Masahiko Sawada Date: Fri, 9 May 2025 17:57:35 -0700 X-Gm-Features: AX0GCFv7rXn-eBSgQ4QkSE9dAVF49bDY217-uKRlhvyXhi_ZTCFJjZYEfbNAhIA Message-ID: Subject: Re: Make COPY format extendable: Extract COPY TO format implementations To: Sutou Kouhei Cc: david.g.johnston@gmail.com, tgl@sss.pgh.pa.us, zhjwpku@gmail.com, michael@paquier.xyz, pgsql-hackers@postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, May 9, 2025 at 2:41=E2=80=AFAM Sutou Kouhei wr= ote: > > Hi, > > In > "Re: Make COPY format extendable: Extract COPY TO format implementation= s" on Sat, 3 May 2025 22:27:36 -0700, > "David G. Johnston" wrote: > > > In any case, I=E2=80=99m doubtful either of us can make a convincing en= ough > > argument to sway the other fully. Both options are plausible, IMO. Ot= hers > > need to chime in. > > I may misunderstand but here is the current summary, right? Thank you for summarizing the discussion. > > Proposed approaches to register custom COPY formats: > a. Create a function that has the same name of custom COPY > format > b. Call a register function from _PG_init() > > FYI: I proposed c. approach that uses a. but it always > requires schema name for format name in other e-mail. With approach (c), do you mean that we require users to change all FORMAT option values like from 'text' to 'pg_catalog.text' after the upgrade? Or are we exempt the built-in formats? > > Users can register the same format name: > a. Yes > * Users can distinct the same format name by schema name > * If format name doesn't have schema name, the used > format depends on search_path > * Pros: > * Using schema for it is consistent with other > PostgreSQL mechanisms > * Custom format never conflict with built-in > format. For example, an extension register "xml" and > PostgreSQL adds "xml" later, they are never > conflicted because PostgreSQL's "xml" is registered > to pg_catalog. > * Cons: Different format may be used with the same > input. For example, "jsonlines" may choose > "jsonlines" implemented by extension X or implemented > by extension Y when search_path is different. > b. No > * Users can use "${schema}.${name}" for format name > that mimics PostgreSQL's builtin schema (but it's just > a string) > > > Built-in formats (text/csv/binary) should be able to > overwritten by extensions: > a. (The current patch is no but David's answer is) Yes > * Pros: Users can use drop-in replacement faster > implementation without changing input > * Cons: Users may overwrite them accidentally. > It may break pg_dump result. > (This is called as "backward incompatibility.") > b. No The summary matches my understanding. I think the second point is important. If we go with a tablesample-like API, I agree with David's point that all FORMAT values including the built-in formats should depend on the search_path value. While it provides a similar user experience to other database objects, there is a possibility that a COPY with built-in format could work differently on v19 than v18 or earlier depending on the search_path value. > Are there any missing or wrong items? I think the approach (b) provides more flexibility than (a) in terms of API design as with (a) we need to do everything based on one handler function and callbacks. > If we can summarize > the current discussion here correctly, others will be able > to chime in this discussion. (At least I can do it.) +1 Regards, --=20 Masahiko Sawada Amazon Web Services: https://aws.amazon.com