Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e6yKE-00041o-5m for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Oct 2017 12:28:54 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e6yKD-0000b5-Op for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Oct 2017 12:28: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_2) (envelope-from ) id 1e6yId-0003Xe-82 for pgsql-hackers@postgresql.org; Tue, 24 Oct 2017 12:27:15 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e6yIa-0001Bp-Er for pgsql-hackers@postgresql.org; Tue, 24 Oct 2017 12:27:14 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 1966621C2040 for ; Tue, 24 Oct 2017 15:27:12 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru Received: from anthony-24-g082ur (unknown [31.173.148.242]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id D05C121C203F for ; Tue, 24 Oct 2017 15:27:11 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1508848031; bh=edenXELDrUZ8VPZQTigwV1q2suTD8RF+pXOHjUN6oow=; h=Date:From:To:Subject:In-Reply-To:References; b=PfD9JH6U8dM+hdZpspsRD7uakItHvxSy67NI8tyGF8bMmBCzEK2z608LlNu+mvqUJ fJOsVjdaxloEcEBKOEQ1hL67QOY1/QbsuHo3NSg1iQvjwyYwa82tXCy1kVkrn6w792 GaQx+YTdamk8MWpUhkVxnubh7YuuP41hqJ5jLjh8= Date: Tue, 24 Oct 2017 15:27:09 +0300 From: Anthony Bykov To: pgsql-hackers@postgresql.org Subject: Re: Transform for pl/perl Message-ID: <20171024152709.641251ae@anthony-24-g082ur> In-Reply-To: <20171024140129.6bd01f68@anthony-24-g082ur> References: <20171024140129.6bd01f68@anthony-24-g082ur> Organization: postgres pro X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 There are some moments I should mention: 1. {"1":1}::jsonb is transformed into HV {"1"=>"1"}, while ["1","2"]::jsonb is transformed into AV ["1", "2"] 2. If there is a numeric value appear in jsonb, it will be transformed to SVnv through string (Numeric->String->SV->SVnv). Not the best solution, but as far as I understand this is usual practise in postgresql to serialize Numerics and de-serialize them. 3. SVnv is transformed into jsonb through string (SVnv->String->Numeric). An example may also be helpful to understand extension. So, as an example, function "test" transforms incoming jsonb into perl, transforms it back into jsonb and returns it. create extension jsonb_plperl cascade; create or replace function test(val jsonb) returns jsonb transform for type jsonb language plperl as $$ return $_[0]; $$; select test('{"1":1,"example": null}'::jsonb); -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers