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 1qsNta-007oiN-I7 for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Oct 2023 13:44:34 +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 1qsNtY-0014rU-80 for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Oct 2023 13:44:32 +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 1qsNtX-0014rA-Qe for pgsql-hackers@lists.postgresql.org; Mon, 16 Oct 2023 13:44:32 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qsNtU-000zOY-4y for pgsql-hackers@postgresql.org; Mon, 16 Oct 2023 13:44:31 +0000 Received: from [192.168.100.8] (109-252-88-77.nat.spd-mgts.ru [109.252.88.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: a.melnikov@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id B544CE20FD5; Mon, 16 Oct 2023 16:44:27 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1697463867; bh=dwIIWVnNmTRJk81mDw+xwOeppUW23TlSundXnicXEow=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=n7l4hNrCIK0GiLXlJMDS3ReAC7dc6cgljFrxEmKCnBN/3qqClbAmbbR2nRyC66g/h TbHk12Y7svglckviBuAAFv3VUB3Lx0sf+Bn7Pprl8I7igq6kRm3L6jcMovPnzhvRHb tzwMRjDr2c9UYYfUJpLwhQHGJC9DuPd6iDZng9I+xpyMMFZgz0RnTsFvGb3EUUGGO/ di0b0zX7GAfDUoycwqHq8vZ9uhlS0Z/hIb2X2xHWFKzBHXMyfrJo0XSs6gGAv/Kt4Y gv9lveoVW3VTOV11ZsqbOmoQ4agLg7xqUFP4rk/O0x5f+A+SkO4CgrDUdKdTb4kLAZ BBSHHheltS9YQ== Message-ID: Date: Mon, 16 Oct 2023 16:44:27 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: remaining sql/json patches Content-Language: en-US To: jian he , Amit Langote Cc: Nikita Malakhov , Andres Freund , Alvaro Herrera , Andrew Dunstan , Erik Rijkers , PostgreSQL-development References: <202309281104.kmkr4v34ny2t@alvherre.pgsql> <20231006214856.yie5dedhzrcb3qxx@alap3.anarazel.de> From: "Anton A. Melnikov" In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello! On 16.10.2023 15:49, jian he wrote: > add the following code after ExecEvalJsonExprCoercion if > (!InputFunctionCallSafe(...) works, but seems like a hack. > > if (!val_string) > { > *op->resnull = true; > *op->resvalue = (Datum) 0; > } It seems the constraint should work here: After CREATE TABLE test ( js text, i int, x jsonb DEFAULT JSON_QUERY(jsonb '[1,2]', '$[*]' WITH WRAPPER) CONSTRAINT test_constraint CHECK (JSON_QUERY(js::jsonb, '$.a' RETURNING char(5) OMIT QUOTES EMPTY ARRAY ON EMPTY) > 'a') ); INSERT INTO test_jsonb_constraints VALUES ('[]'); one expected to see an error like that: ERROR: new row for relation "test" violates check constraint "test_constraint" DETAIL: Failing row contains ([], null, [1, 2]). not "INSERT 0 1" With best regards, -- Anton A. Melnikov Postgres Professional: http://www.postgrespro.com The Russian Postgres Company