Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cWVTN-0005PM-1Y for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Jan 2017 21:51:21 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cWVTM-00061B-GH for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Jan 2017 21:51:20 +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 1cWVRw-0003yd-T5 for pgsql-hackers@postgresql.org; Wed, 25 Jan 2017 21:49:53 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cWVRs-0001HE-AL for pgsql-hackers@postgresql.org; Wed, 25 Jan 2017 21:49:51 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v0PLnh6H016180; Wed, 25 Jan 2017 16:49:43 -0500 From: Tom Lane To: Nikita Glukhov cc: Aleksander Alekseev , Michael Paquier , PostgreSQL mailing lists Subject: Re: PATCH: recursive json_populate_record() In-reply-to: <295ad4a5-2923-1834-5140-35d0b9a5818c@postgrespro.ru> References: <222c7cfb-73c8-a56e-7844-3dc51682760d@postgrespro.ru> <20161227131541.GA6976@e733.localdomain> <1b72a62e-fd94-fd6d-c573-870af0c8600d@postgrespro.ru> <11489.1483901523@sss.pgh.pa.us> <687e19a7-14e2-d0f5-2bff-35d62bc5c05a@postgrespro.ru> <934.1485111512@sss.pgh.pa.us> <9e21a39c-c1d7-b9b5-44a0-c5345a5029f6@postgrespro.ru> <13020.1485377905@sss.pgh.pa.us> <295ad4a5-2923-1834-5140-35d0b9a5818c@postgrespro.ru> Comments: In-reply-to Nikita Glukhov message dated "Thu, 26 Jan 2017 00:36:53 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <16178.1485380983.1@sss.pgh.pa.us> Date: Wed, 25 Jan 2017 16:49:43 -0500 Message-ID: <16179.1485380983@sss.pgh.pa.us> X-Pg-Spam-Score: -5.1 (-----) 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 Nikita Glukhov writes: > On 25.01.2017 23:58, Tom Lane wrote: >> I think you need to take a second look at the code you're producing >> and realize that it's not so clean either. This extract from >> populate_record_field, for example, is pretty horrid: > But what if we introduce some helper macros like this: > #define JsValueIsNull(jsv) \ > ((jsv)->is_json ? !(jsv)->val.json.str \ > : !(jsv)->val.jsonb || (jsv)->val.jsonb->type == jbvNull) > #define JsValueIsString(jsv) \ > ((jsv)->is_json ? (jsv)->val.json.type == JSON_TOKEN_STRING \ > : (jsv)->val.jsonb && (jsv)->val.jsonb->type == jbvString) Yeah, I was wondering about that too. I'm not sure that you can make a reasonable set of helper macros that will fix this, but if you want to try, go for it. BTW, just as a stylistic thing, I find "a?b:c||d" unreadable: I have to go back to the manual every darn time to convince myself whether that means (a?b:c)||d or a?b:(c||d). It's better not to rely on the reader (... or the author) having memorized C's precedence rules in quite that much detail. Extra parens help. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers