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 1os5xZ-00024K-Gt for pgsql-general@arkaria.postgresql.org; Mon, 07 Nov 2022 17:30: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 1os5wa-0002eH-Cw for pgsql-general@arkaria.postgresql.org; Mon, 07 Nov 2022 17:29:56 +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 1os5wa-0002e5-0s for pgsql-general@lists.postgresql.org; Mon, 07 Nov 2022 17:29:56 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1os5wX-0003KD-KD for pgsql-general@lists.postgresql.org; Mon, 07 Nov 2022 17:29:54 +0000 Received: by mail-pj1-x102d.google.com with SMTP id d59-20020a17090a6f4100b00213202d77e1so15322650pjk.2 for ; Mon, 07 Nov 2022 09:29:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=Uo6jzemCF0y4GrwDRd3TEe3JUsxuLW9Dbd1WMRJt5Og=; b=WBWE86OeBgMiXDQAje97577NqhTzRQA7vGt/CTv4bcLidH/8mxzmgL/lfrENlHi0Qi eNt5UMfoJiPF4362UNFTqSp3H/5es5+tAzcUUwr9T2b780nD72zIapfY5NlH4rvDAMbb g9ln96DknXdTzTa80wKpG7nHHdoF075pKQbBuj/JrOZ2Vpd2cyJfxjXJjD1BlBzvuZXq NjAe9JjFQteQYKhlf89VjBR4C9BY/+39u0402UDEuilu7GHKBAgcGFbcqXYCf0xehDRH CdkONMJbQFdZ9d5swkX0WEY+TPGK2tA2iJyJbrpzOqOB/A/XmZubG6dVtCVHo67i+rTD g7Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=Uo6jzemCF0y4GrwDRd3TEe3JUsxuLW9Dbd1WMRJt5Og=; b=PJ6aJScj0AWMdL0kKIltpW8IhUjYN+DICuoNESX5/Dhmeb3fxIhNZjTiXAEuqcnnhp 0QHKuGklk4p/G5hbf+ndSqXSQY0fPNZuMUNHn8xoOjU9Rr94lenLVRuNUc/mm+sBkID9 F8BU9IefzUasen4TetBZZn6OhdRb2xpLcoUkFDXYGm/PZ88rxXTr2sWFLJH1S3qyGU5y c1VKY92iPCjVfggM1oNDJz4x/VuVx6JDFK038gQstXV8/hz9EogaFQcInUFLUFBAyO9U jzJTS4LwNmakEKORt1JancakmEfC0H5fxL1/6Dixppjt5wOer9E3jvTO3oT7l2z/y35v 2Zuw== X-Gm-Message-State: ANoB5pmGWds7mN3LciBrOnsCxyVmbzdYTAEgptTGwe5p5qItzuI068PX nCnWugJzkKUUT7coOhivlbcjjAd/LOw= X-Google-Smtp-Source: AA0mqf5GLeB87w1LCzOKJjGSVRQMaRGTNvIc1JRtjiw+JmJAjliwCZOxYMJVuTQosDcOdv7lPpQRYA== X-Received: by 2002:a17:902:e743:b0:188:6fc8:565c with SMTP id p3-20020a170902e74300b001886fc8565cmr15160494plf.106.1667842191915; Mon, 07 Nov 2022 09:29:51 -0800 (PST) Received: from [10.128.56.149] ([155.98.131.5]) by smtp.gmail.com with ESMTPSA id p18-20020a170902ebd200b00176b63535adsm5213744plg.260.2022.11.07.09.29.50 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 07 Nov 2022 09:29:51 -0800 (PST) Content-Type: multipart/alternative; boundary="------------GFJ4DOjve2EP0CV2SM2wfaWk" Message-ID: Date: Mon, 7 Nov 2022 10:29:49 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: copy file from a client app to remote postgres isntance Content-Language: en-CA To: pgsql-general@lists.postgresql.org References: From: Rob Sargent In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------GFJ4DOjve2EP0CV2SM2wfaWk Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 11/7/22 09:57, Вадим Самохин wrote: > Hi all, > I have an application that must copy a local file in csv format to a > postgres table on a remote host. The closest solution is this one > (https://stackoverflow.com/a/9327519/618020 > ). It boils down to > specifying a \copy meta-command in a psql command: > |psql -U %s -p %s -d %s -f - < \nEOT\n ||and executing it. B|ut it's quite an unnatural way to write database > code. Has anything changed in the last ten years? Or, is there a > better wayto copy file contents in a remote database? There are bulk copy routines available. What is your architecture? --------------GFJ4DOjve2EP0CV2SM2wfaWk Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 11/7/22 09:57, Вадим Самохин wrote:
Hi all,
I have an application that must copy a local file in csv format to a postgres table on a remote host. The closest solution is this one (https://stackoverflow.com/a/9327519/618020). It boils down to specifying a \copy meta-command in a psql command:
psql -U %s -p %s -d %s -f - <<EOT\n here hoes a \copy meta-command \nEOT\n

and executing it. But it's quite an unnatural way to write database code. Has anything changed in the last ten years? Or, is there a better way to copy file contents in a remote database?
There are bulk copy routines available.  What is your architecture?  --------------GFJ4DOjve2EP0CV2SM2wfaWk--