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 1uaDUj-001QcH-NF for pgsql-general@arkaria.postgresql.org; Fri, 11 Jul 2025 13:08:53 +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 1uaDTh-004ojd-Il for pgsql-general@arkaria.postgresql.org; Fri, 11 Jul 2025 13:07:50 +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 1uaDTh-004ojV-6m for pgsql-general@lists.postgresql.org; Fri, 11 Jul 2025 13:07:49 +0000 Received: from mail-oo1-xc33.google.com ([2607:f8b0:4864:20::c33]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uaDTg-006lKM-0Y for pgsql-general@lists.postgresql.org; Fri, 11 Jul 2025 13:07:48 +0000 Received: by mail-oo1-xc33.google.com with SMTP id 006d021491bc7-611e455116aso1177455eaf.1 for ; Fri, 11 Jul 2025 06:07:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752239267; x=1752844067; darn=lists.postgresql.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=0POBrvvdy6ytGgjnbUFStqvslCDUWuSnPenKChI2FSg=; b=ebl2T9icdiq/6tC+ebnH5iRcDSh9ut69UrQrCybFvqoPF3Xe+cSb5OgMZdgKoPLQUJ x6I7fxouqNa8qzyQ5I2z+t09f6Rck455q6Xzyaz+IPIaEzFD0Y2/Fs5vwud4jj2p/2aL XIOdOYm5+sOp4bCyCEPlozD7IDEt0qbcgQbPWqDLlfFBCS3Xbugq8prGmhZlXevepObx EFHxpKHl8/8AfGmSRXvOyx398Fip+F6AIyDMqWFIol1i0KtXqBg99UjmzmNxzLMs01+o WruSwirOG+vmF2goUddT9j6wg4YrNCHvvJ4u84Gg7Z+fkBoMWjygGSxoyRpWr4v8Zb3A qPug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752239267; x=1752844067; h=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=0POBrvvdy6ytGgjnbUFStqvslCDUWuSnPenKChI2FSg=; b=s+TmUteevR3uV7K8NzTizA1fAlsRcmQWBEfsutJXO21+sVvD6VFIUtcMvn4ufarGWh CdIRe9AuEng3DjetRmL7/NxH356gOaUIFM53qxbwvw0NYrUuyAY5T1ZL7OtntKnCZWDP ahuzr+frgw+hsN++ASJlFosSp5WCUOwui7qIrl6lTcPzKZW0qeqZmEW11+soQ4ddvTF3 7ZxFJEGV2qtZFo31VajmZ4VWCIPKsPKjL9tXboT9RDpoNeigMGt/084yHXjhZEKK7waU YU6QgAUA2nwwJMD0Qqgh9AI86uCFnGr2CC3i/7iGePLaLJ6XyXur8dGVr8wAbjvwT4LT DOmg== X-Gm-Message-State: AOJu0Yzl7AS2LlhLAwpksibgmq6t/5Ce5co5vxycpnlOPznqNaOkuZ/E avvPBv9MC2uPT4NQH01WHQVAHqbQDhnoS2loc1F9mQXQDnEGBcVSD90Gbx6dfOfmzD4tEKV1O3M H8eVtiy7MApkCvWWXF5ImRtkJvlAqLQ5W5w== X-Gm-Gg: ASbGncueq8rfz7lT0RFLiO7+k7pizFEap2cIDwfGeWaw90fa+hSk6F+nLuhcQuG2kJs nZNhHqYATazeCZQqW1CGEByVdv/QxoJ5PQC+78AfM4HRQ3io0Q8G/NDBuBY87Zq5N8gv4ovNRi2 I2YmkLRCgHjqKtyF3yOQX64qQ66CR8gp2vF5pao6pcDYXXy/iNbxDEJ27vZ8aU+TKpAeuEw5WCA MUGw5+4HYMoL8n37BcddNuUn0oMzCbZLc42QEQ7 X-Google-Smtp-Source: AGHT+IGZKegL7YimnTSTKP3xxLok4HNeZqNHacg75qDKiagDfs2W99b/aGGGCuBCVr+fvTac4w15ETthjZhmqAml7U8= X-Received: by 2002:a05:6820:2715:b0:613:c3e6:10f5 with SMTP id 006d021491bc7-613e5fc625bmr2186512eaf.5.1752239263808; Fri, 11 Jul 2025 06:07:43 -0700 (PDT) MIME-Version: 1.0 References: <43b9fb8c.8b5c.197f96e3544.Coremail.gzhcoder@126.com> In-Reply-To: <43b9fb8c.8b5c.197f96e3544.Coremail.gzhcoder@126.com> From: Ron Johnson Date: Fri, 11 Jul 2025 09:07:32 -0400 X-Gm-Features: Ac12FXy1kMW23QbRwQf8fqxoekzV84JqkVLzWZmNDOoXoFsWjzhsTdSE2WlOj3k Message-ID: Subject: Re: Question Regarding COPY Command Handling of Line Breaks in PostgreSQL To: "pgsql-generallists.postgresql.org" Content-Type: multipart/alternative; boundary="000000000000e1865b0639a6fe61" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000e1865b0639a6fe61 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Jul 11, 2025 at 8:20=E2=80=AFAM gzh wrote: > Dear, > > I am encountering an issue with the COPY command in PostgreSQL regarding > the handling of line breaks in data fields. My PostgreSQL instance is > installed on a Linux system. > > When I use the COPY command to export data to a CSV file and then import > the same CSV file back into the database, all carriage return characters > (CR) in the fields are automatically converted to line feed characters > (LF). For example: > > Field content before import: *** (CR) *** > Field content after import: *** (LF) *** > I would like to know if there is a way to use the COPY command while > preserving the original line breaks (CR) in the data fields during import= . > What PG version? What's the full command (including both shell and SQL commands)? --=20 Death to , and butter sauce. Don't boil me, I'm still alive. lobster! --000000000000e1865b0639a6fe61 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Fri, Jul 11, 2025 at 8:20=E2=80=AFAM g= zh <gzhcoder@126.com> wrote:<= /div>
Dear,

I am= encountering an issue with the COPY command in PostgreSQL regarding the ha= ndling of line breaks in data fields. My PostgreSQL instance is installed o= n a Linux system.

When I use the COPY command to e= xport data to a CSV file and then import the same CSV file back into the da= tabase, all carriage return characters (CR) in the fields are automatically= converted to line feed characters (LF). For example:

<= div>Field content before import: *** (CR) ***
Field content after= import: *** (LF) ***
I would like to know if there is a way to u= se the COPY command while preserving the original line breaks (CR) in the d= ata fields during import.
=C2=A0
What PG version?
What's the full command (including both s= hell and SQL commands)?

--
Death to <Redacted>, and butter sauce.
Don't boil me= , I'm still alive.
<Redacted> lobster!
--000000000000e1865b0639a6fe61--