Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e8s3H-0004gi-Mc for pgsql-hackers@arkaria.postgresql.org; Sun, 29 Oct 2017 18:11:15 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e8s3G-0003m0-FQ for pgsql-hackers@arkaria.postgresql.org; Sun, 29 Oct 2017 18:11:14 +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_2) (envelope-from ) id 1e8s3E-0003ju-NU for pgsql-hackers@postgresql.org; Sun, 29 Oct 2017 18:11:12 +0000 Received: from xvm-110-146.dc2.ghst.net ([46.226.110.146] helo=fetter.org) by makus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e8s37-0007ak-O9 for pgsql-hackers@postgresql.org; Sun, 29 Oct 2017 18:11:11 +0000 Received: by fetter.org (Postfix, from userid 1001) id 24B8A40EF8; Sun, 29 Oct 2017 19:11:03 +0100 (CET) Date: Sun, 29 Oct 2017 19:11:02 +0100 From: David Fetter To: Anthony Bykov Cc: pgsql-hackers@postgresql.org Subject: Re: Jsonb transform for pl/python Message-ID: <20171029181102.GA2786@fetter.org> References: <20171025145100.3a19933f@anthony-24-g082ur> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171025145100.3a19933f@anthony-24-g082ur> User-Agent: Mutt/1.5.24 (2015-08-30) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On Wed, Oct 25, 2017 at 02:51:00PM +0300, Anthony Bykov wrote: > Hi. > I've implemented jsonb transform > (https://www.postgresql.org/docs/9.5/static/sql-createtransform.html) > for pl/python. > > 1. '{"1":1}'::jsonb is transformed into dict {"1"=>1}, while > '["1",2]'::jsonb is transformed into list(not tuple!) ["1", 2] > > 2. If there is a numeric value appear in jsonb, it will be transformed > to decimal through string (Numeric->String->Decimal). Not the best > solution, but as far as I understand this is usual practise in > postgresql to serialize Numerics and de-serialize them. > > 3. Decimal is transformed into jsonb through string > (Decimal->String->Numeric). > > An example may also be helpful to understand extension. So, as an > example, function "test" transforms incoming jsonb into python, > transforms it back into jsonb and returns it. > > create extension jsonb_plpython2u cascade; Thanks for your hard work! Should there also be one for PL/Python3U? Best, David. -- David Fetter http://fetter.org/ Phone: +1 415 235 3778 Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers