Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aOr24-0000O5-W9 for pgsql-sql@arkaria.postgresql.org; Thu, 28 Jan 2016 18:11:01 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aOr24-0000x6-DI for pgsql-sql@arkaria.postgresql.org; Thu, 28 Jan 2016 18:11:00 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aOr22-0000up-5j for pgsql-sql@postgresql.org; Thu, 28 Jan 2016 18:10:58 +0000 Received: from outbound003.hypermediasystems.com ([66.162.38.157] helo=outbound003.inf) by makus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1aOr1y-0003vH-Bq for pgsql-sql@postgresql.org; Thu, 28 Jan 2016 18:10:55 +0000 Received: from mail021.dti ([10.5.4.195]) by outbound003.inf with ESMTP; 28 Jan 2016 18:10:53 +0000 Received: from mail021.dti (mail021.dti [10.5.4.195]) by mail021.dti (Postfix) with ESMTP id 4151815410035 for ; Thu, 28 Jan 2016 10:10:53 -0800 (PST) Date: Thu, 28 Jan 2016 10:10:53 -0800 (PST) From: Arthur Lewis To: pgsql-sql@postgresql.org Message-ID: <1668948418.7183478.1454004653187.JavaMail.root@hypermediasystems.com> In-Reply-To: <794130325.7183384.1454004350562.JavaMail.root@hypermediasystems.com> Subject: insert a text file into a variable in order to insert into a bytea column MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [10.40.10.119] X-Mailer: Zimbra 7.2.2_GA_2852 (ZimbraWebClient - FF3.0 (Linux)/7.2.2_GA_2852) X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org Hello, I have a file called file.txt that is 53604 bytes. When I do the following \set stext `cat file.txt` select length(:'stext'); length -------- 53603 it seems that one byte (the last newline character) is chomped off. How can I import a text file into a variable and insert it into a bytea column without losing the last newline byte. What I want to do is something like this: \set stext `cat file.txt` insert into stored_files (file_name,file_text) values ('file',:'stext'); without losing a character within the variable stext. In table stored_files, file_name is text and file_text is bytea. I'm using psql 9.3.10 on Ubuntu 14 Linux (32 bit.) I cannot use pg_read_file because that is for the server side, and I'm on the client side. There should be an easy way to get a text file into a database column. Thank you, Arthur Lewis -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql