Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qp7lb-004Rqa-HB for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Oct 2023 13:54:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qp7lW-00HKW7-UO for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Oct 2023 13:54:47 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qp7lV-00HKVz-Rk for pgsql-hackers@lists.postgresql.org; Sat, 07 Oct 2023 13:54:47 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qp7lS-000m76-8Y for pgsql-hackers@postgresql.org; Sat, 07 Oct 2023 13:54:45 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailout.west.internal (Postfix) with ESMTP id 0B4F532009F9; Sat, 7 Oct 2023 09:54:37 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Sat, 07 Oct 2023 09:54:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1696686877; x= 1696773277; bh=pkBjmPQGdFPJ4EPusaIgLNYNe05fj0dPL6c1AZK7J4I=; b=g Rheu4S6O+gabeOmSLyZbGnJ8Fzi77OFwlOudPllZN0Ur6JKH3PzH04Ox8JQAwLlS 29ec3bmNRpMr7j6IWJj/SuwvahhwscW+nVLDqqVA3UhHUUJBLtKIlba1Pv4b7VjO tDUmCBqiJr4me9PcUkfxqXBPBNsZDnTuX/Xl8nC0FhH4SRfCV5r+tJPxCNXrG4Q2 7C7wJ6VLt+ATmEO9hI3vU5BgFCaPGh3lN7jayDes7AzA2wAnSnh7/K3QoY0WIzam Hd9Eh3L/qZZwJwxEye+ntBHFZ+oFE3FY0PWGeGUmoHquvfyp7nS9RKhqDs8J5vDb CAtDqX5+Fbfdt/OrV4LiQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrgeelgdejtdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfggtggugfgjsehtkeertddttdejnecuhfhrohhmpeetlhhvrghr ohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgqe enucggtffrrghtthgvrhhnpedvkedtffduffdtffffheffhfejjefhgfeiueeukeejkeff gfdufffhudffffeuveenucffohhmrghinhepvghnthgvrhhprhhishgvuggsrdgtohhmne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghlvhhh vghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 7 Oct 2023 09:54:36 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1696686873; bh=t2aONMFdQ2SiX/zCPDJzSRthIvfNkrLg8ZrFnsF4KQc=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=iqzvmLjNom717HEjE1Bsg2LlsRPKnmY6sDNSf1kobzfyWuMVULjDrSAhRh29O/hGn Mf5CufUFZMAwMj/X+WU0tEMLzNYdLSL23ry9/NkfQH3+QInUSu4OOj7FoPn2qm7zkf l8RIDjpvjPiO1XLSmdUMJsUxWWs5LJ9Eq5416uCmq64bHp0gMdyqH/LjVu9mcf2tKe wk/RLqeRGjnkWgWB4+kACW9PMKU6CRySpW5LoQfjdppg09OpI/VNuOcQXxb7aFG5Hu Yg7Aapt4Oz957dWCav1f1XVdqV/T7f4WYMUwaCaBugp1zcXZv/O3F3yAlwdvdJeAYP aOLS3HVkZPqEQ== Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 8B9EA3146; Sat, 7 Oct 2023 15:54:33 +0200 (CEST) Date: Sat, 7 Oct 2023 15:54:33 +0200 From: Alvaro Herrera To: Andres Freund Cc: Amit Langote , Andrew Dunstan , jian he , Erik Rijkers , PostgreSQL-development Subject: Re: remaining sql/json patches Message-ID: <202310071354.yljfgk2jgvvr@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231006214856.yie5dedhzrcb3qxx@alap3.anarazel.de> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2023-Oct-06, Andres Freund wrote: > > +json_query_behavior: > > + ERROR_P { $$ = makeJsonBehavior(JSON_BEHAVIOR_ERROR, NULL, @1); } > > + | NULL_P { $$ = makeJsonBehavior(JSON_BEHAVIOR_NULL, NULL, @1); } > > + | DEFAULT a_expr { $$ = makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); } > > + | EMPTY_P ARRAY { $$ = makeJsonBehavior(JSON_BEHAVIOR_EMPTY_ARRAY, NULL, @1); } > > + | EMPTY_P OBJECT_P { $$ = makeJsonBehavior(JSON_BEHAVIOR_EMPTY_OBJECT, NULL, @1); } > > + /* non-standard, for Oracle compatibility only */ > > + | EMPTY_P { $$ = makeJsonBehavior(JSON_BEHAVIOR_EMPTY_ARRAY, NULL, @1); } > > + ; > > > +json_exists_behavior: > > + ERROR_P { $$ = makeJsonBehavior(JSON_BEHAVIOR_ERROR, NULL, @1); } > > + | TRUE_P { $$ = makeJsonBehavior(JSON_BEHAVIOR_TRUE, NULL, @1); } > > + | FALSE_P { $$ = makeJsonBehavior(JSON_BEHAVIOR_FALSE, NULL, @1); } > > + | UNKNOWN { $$ = makeJsonBehavior(JSON_BEHAVIOR_UNKNOWN, NULL, @1); } > > + ; > > + > > +json_value_behavior: > > + NULL_P { $$ = makeJsonBehavior(JSON_BEHAVIOR_NULL, NULL, @1); } > > + | ERROR_P { $$ = makeJsonBehavior(JSON_BEHAVIOR_ERROR, NULL, @1); } > > + | DEFAULT a_expr { $$ = makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); } > > + ; > > This also seems like it could use some dedup. Yeah, I was looking at this the other day and thinking that we should just have a single json_behavior that's used by all these productions; at runtime we can check whether a value has been used that's improper for that particular node, and error out with a syntax error or some such. Other parts of the grammar definitely needs more work, too. It appears to me that they were written by looking at what the standard says, more or less literally. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "Someone said that it is at least an order of magnitude more work to do production software than a prototype. I think he is wrong by at least an order of magnitude." (Brian Kernighan)