Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aOrAf-0000ja-TJ for pgsql-sql@arkaria.postgresql.org; Thu, 28 Jan 2016 18:19:54 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aOrAe-0004iH-V7 for pgsql-sql@arkaria.postgresql.org; Thu, 28 Jan 2016 18:19:53 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aOrAe-0004hl-7M for pgsql-sql@postgresql.org; Thu, 28 Jan 2016 18:19:52 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aOrAa-0005NO-Ce for pgsql-sql@postgresql.org; Thu, 28 Jan 2016 18:19:51 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 6B00720966 for ; Thu, 28 Jan 2016 13:19:46 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute3.internal (MEProxy); Thu, 28 Jan 2016 13:19:46 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=4d8gmWSlWM8s/L2G1uyvHFP9Gdk=; b=bnF/pv 4xeK8ldlJYEI6PSJt7sk1aftOYsaAhGp0d/r3gfRAaTCZQjEnUc4OqZDoFIQLVqG ybJgn6/ZR643unRb1XCBLTaq7WE6RVdj7h7yh0G0tlIL3ofWwaYVkYK4mpKxH1pA BWahlC/ozECzGhiAQ6CRy2itm23w/TTMtDPqI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=4d8gmWSlWM8s/L2 G1uyvHFP9Gdk=; b=k8tX6+wrAyYmuLURERacaangreWIUy5a/SORAw8/S09TGCs LjDDr+e3Ri02ztN8xF6fWNpGedaK+zwXtp92Y9P8LORYzxh0upArBxzbHEqkM6pm FVLHLuEIMUUyI9q52RGX1nwkomojGQMdwGqFPWHGnkHLLAi/hMmvH/6qIJ4E= X-Sasl-enc: haWjInRb71AqSMEShNcEPPd0LGDSIW83BUpydlCl/NdB 1454005185 Received: from killi.site (173-160-167-74-washington.hfc.comcastbusiness.net [173.160.167.74]) by mail.messagingengine.com (Postfix) with ESMTPA id A3EEAC00018; Thu, 28 Jan 2016 13:19:45 -0500 (EST) Subject: Re: insert a text file into a variable in order to insert into a bytea column To: Arthur Lewis , pgsql-sql@postgresql.org References: <1668948418.7183478.1454004653187.JavaMail.root@hypermediasystems.com> From: Adrian Klaver Message-ID: <56AA5BFB.30808@aklaver.com> Date: Thu, 28 Jan 2016 10:20:43 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <1668948418.7183478.1454004653187.JavaMail.root@hypermediasystems.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.7 (--) 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 On 01/28/2016 10:10 AM, Arthur Lewis wrote: > 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. Are sure it is not cat that is chomping the byte?: aklaver@killi:~> cat test.txt Test second line aklaver@killi:~> cat -A test.txt Test$ second line$ > > 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 > > -- Adrian Klaver adrian.klaver@aklaver.com -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql