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 1rk0uh-009ecd-Ph for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Mar 2024 12:07:24 +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 1rk0uf-00BP7K-Vz for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Mar 2024 12:07:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rk0uf-00BP7C-Mk for pgsql-hackers@lists.postgresql.org; Tue, 12 Mar 2024 12:07:22 +0000 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rk0uc-00478n-LE for pgsql-hackers@postgresql.org; Tue, 12 Mar 2024 12:07:20 +0000 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1dd9b6098aeso16769795ad.0 for ; Tue, 12 Mar 2024 05:07:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710245239; x=1710850039; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=CyHBqeiCPIo0XONTv5Z6OQawk6FUI+Ei2JXKznPlXnk=; b=CepevWdtu1HxvwUJgC+Jxx9Q1sPb6pmCzfH/MR4BvePH9l2WL4F1pRq9DuIkIl/1Ct 3WuRxbDbT9DvRcmTBOdJ9jgsyoCur6W3t177oG2wPs7aBtIua5rAnOm8RtTcivMChGSk a6siC2NcmsVl0RzB25zJZAdfVSgGZtPr/BuGVE/Hs6bql+Qqm1/X3sI8wOCxs3rUCdZh 6U763OuW86eHNmjtmuK02Csun78rQR3qspTaGb8yEDgXoasuafJPuwQrVja06ZxRuELS 7Hdc0jJQOnyRCd5C3lbVV0ycRUrKfi3l+mgWGW7+zuzPqH4GklLqLtRz53oYnvjbyjef RIQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710245239; x=1710850039; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CyHBqeiCPIo0XONTv5Z6OQawk6FUI+Ei2JXKznPlXnk=; b=WB+8nck6mfXSNx9kNiURM3Ft81xX2xY7R337jURCSq83k42XIk6QQDS8WefOCmTMPO r1UNSB29V4cR9lezZhSVywaZhR9g+pxoLE7MCOj1axtdXuiCeDVHrXh5XJNiLHesZLmE zrvcYxPuoyRXTDLkxKPVvhuuu6IWjEVpjVLzQcLbvfXUBGLbZQnk5YCkDIu3Gmaee1O2 DM7z1vs4rlmvENRhHaPgUXIBpZ2+LL6TXmpNkjfH+Vtt3cDUhfnKGedBtjlC3HndQbEY 4D898B0MGAdlrL3TbzLdBU8eWUE9OA3bZ7h+KyajG0rQ1wQTwgPaDa/ExIRChsNxrbdc 70pA== X-Forwarded-Encrypted: i=1; AJvYcCXta0DayRrbiuPGc+BGN2OZN7zhffnJ/HVIgFas9J5HilOZGs10SLt72i5GABg2FWs5f/MbUuT2karGpJ7azNQpiSm5pvE8xkssIV1H X-Gm-Message-State: AOJu0YzNy+ADkP2C7udCIcwD/RDvdqp4nI7gVios5zzaaVV6xxVuluB4 E67H5FmDKOoeqBhn81EqfYsClgbYH26hyM8DybuclPcJgldYzBtDB+CvwgjVXSJg7Cgild3WOEi l0u9+2Y6TwoCXWiN8WV5v80lUkL4= X-Google-Smtp-Source: AGHT+IF3KOKIBSbkRnjVLAQB9yThkPBkEttN/DvbyVnGX3XjQbdoftLTKB+S/Pbo0Ap7aDGsUWU0yBHA/NzVXB/vUEk= X-Received: by 2002:a17:902:ce02:b0:1dd:878d:9dca with SMTP id k2-20020a170902ce0200b001dd878d9dcamr100323plg.48.1710245238616; Tue, 12 Mar 2024 05:07:18 -0700 (PDT) MIME-Version: 1.0 References: <202403111534.xii7yxswadef@alvherre.pgsql> In-Reply-To: From: Amit Langote Date: Tue, 12 Mar 2024 21:07:01 +0900 Message-ID: Subject: Re: remaining sql/json patches To: Himanshu Upadhyaya Cc: Alvaro Herrera , jian he , Andres Freund , Andrew Dunstan , Erik Rijkers , PostgreSQL-development , Tomas Vondra Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Himanshu, On Tue, Mar 12, 2024 at 6:42=E2=80=AFPM Himanshu Upadhyaya wrote: > > Hi, > > wanted to share the below case: > > =E2=80=98postgres[146443]=3D#=E2=80=99SELECT JSON_EXISTS(jsonb '{"custome= r_name": "test", "salary":1000, "department_id":1}', '$.* ? (@=3D=3D $dept_= id && @ =3D=3D $sal)' PASSING 1000 AS sal, 1 as dept_id); > json_exists > ------------- > f > (1 row) > > isn't it supposed to return "true" as json in input is matching with both= the condition dept_id and salary? I think you meant to use || in your condition, not &&, because 1000 !=3D 1. See: SELECT JSON_EXISTS(jsonb '{"customer_name": "test", "salary":1000, "department_id":1}', '$.* ? (@ =3D=3D $dept_id || @ =3D=3D $sal)' PASSING 1= 000 AS sal, 1 as dept_id); json_exists ------------- t (1 row) Or you could've written the query as: SELECT JSON_EXISTS(jsonb '{"customer_name": "test", "salary":1000, "department_id":1}', '$ ? (@.department_id =3D=3D $dept_id && @.salary =3D= =3D $sal)' PASSING 1000 AS sal, 1 as dept_id); json_exists ------------- t (1 row) Does that make sense? In any case, JSON_EXISTS() added by the patch here returns whatever the jsonpath executor returns. The latter is not touched by this patch. PASSING args, which this patch adds, seem to be working correctly too. --=20 Thanks, Amit Langote