Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aTXjS-0004HF-Pv for pgsql-sql@arkaria.postgresql.org; Wed, 10 Feb 2016 16:35:10 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aTXjS-0007Kn-Cc for pgsql-sql@arkaria.postgresql.org; Wed, 10 Feb 2016 16:35:10 +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 1aTXiT-0005Uy-1j for pgsql-sql@postgresql.org; Wed, 10 Feb 2016 16:34:09 +0000 Received: from [66.111.4.29] (helo=out5-smtp.messagingengine.com) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aTXiO-0005QL-Ry for pgsql-sql@postgresql.org; Wed, 10 Feb 2016 16:34:07 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 103CB21443 for ; Wed, 10 Feb 2016 11:33:41 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute2.internal (MEProxy); Wed, 10 Feb 2016 11:33:41 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=aklaver.com; h=cc :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=/VbD5y4TRGWIACBJ9zn0qH46v10=; b=Hb0zTh N6hAu7gGAPwKHZF4RZIc+tSgjVOtPUEhkoWzISrkZBdwMV1Qo/oV6+1vTYPA55+j Ptnp/0KkuaTm/sRWsfdbphQ1KlpIzMj0A46pu/Z/QHikqkPmC9egBzAISYLtBohK r0XPkPFF6CJLEnnGw3fq6ssDA3jpp5RT3jXo4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=/VbD5y4TRGWIACB J9zn0qH46v10=; b=IOJUslxtmxpMFpDYJ2swukO9WxjhSsUmmRTPK9LA2v7Ov1/ Gy1wTVpgif/XV49RyHV1VzJ6uWBItLnDrgwcbkZ6Su5EdETgHCFOMB0Rw9kKuOw+ Vos3HprvDixW0nZ/SGmBSTjhd0bDd1REDGvZUXzh6LbUn01TwkEtsSQCWcA0= X-Sasl-enc: 63ya86r74xw8B3PjMYLBZi1BwL+z2rOssdz/PeJ5NNtJ 1455122020 Received: from killi.site (173-160-167-74-washington.hfc.comcastbusiness.net [173.160.167.74]) by mail.messagingengine.com (Postfix) with ESMTPA id 84E98C00014; Wed, 10 Feb 2016 11:33:40 -0500 (EST) Subject: Re: inserting json content from a file into table column To: Shashank Dutt Jha References: <56BB55C1.4060305@aklaver.com> Cc: pgsql-sql@postgresql.org From: Adrian Klaver Message-ID: <56BB66A6.1070705@aklaver.com> Date: Wed, 10 Feb 2016 08:34:46 -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: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 66.111.4.29 (deferred) 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 On 02/10/2016 08:01 AM, Shashank Dutt Jha wrote: > psql. PostgreSQL v9.5 A quick and dirty method: aklaver@test=> create table json_test(id integer, json_fld jsonb); CREATE TABLE aklaver@test=> \e sample.json \e opens an editor. Inside editor add INSERT statement to file: INSERT INTO json_test VALUES(1, ' { "glossary": { "title": "example glossary", "GlossDiv": { "title": "S", "GlossList": { "GlossEntry": { "ID": "SGML", "SortAs": "SGML", "GlossTerm": "Standard Generalized Markup Language", "Acronym": "SGML", "Abbrev": "ISO 8879:1986", "GlossDef": { "para": "A meta-markup language, used to create markup languages such as DocBook.", "GlossSeeAlso": ["GML", "XML"] }, "GlossSee": "markup" } } } } }'); aklaver@test=> \x Expanded display is on. aklaver@test=> select * from json_test; -[ RECORD 1 ]----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- id | 1 json_fld | {"glossary": {"title": "example glossary", "GlossDiv": {"title": "S", "GlossList": {"GlossEntry": {"ID": "SGML", "Abbrev": "ISO 8879:1986", "SortAs": "SGML", "Acronym": "SGML", "GlossDef": {"para": "A meta-markup language, used to create markup languages such as DocBook.", "GlossSeeAlso": ["GML", "XML"]}, "GlossSee": "markup", "GlossTerm": "Standard Generalized Markup Language"}}}}} Otherwise you will need to find a way to pass the file in from the shell. You are using Windows it seems and I am not familiar enough with it to offer any guidance on that topic. > > On Wed, Feb 10, 2016 at 8:52 PM, Adrian Klaver > > wrote: > > On 02/10/2016 07:10 AM, Shashank Dutt Jha wrote: > > I have .json file.C:/ a.json > Table with column 'food' of type jsonb > > how to insert the content of a.json into column 'food' > > > What are you using as your client, for example psql, Java program, > Python program, etc.? > > What version of Postgres are you using? In this case it probably > does not matter that much, but json/jsonb has changed a good deal > over recent versions so it is nice to know what you are working with. > > > -- > Adrian Klaver > adrian.klaver@aklaver.com > > -- 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