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 1rmTVK-0085Et-9o for pgsql-general@arkaria.postgresql.org; Tue, 19 Mar 2024 07:03:23 +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 1rmTVI-00ALvL-J2 for pgsql-general@arkaria.postgresql.org; Tue, 19 Mar 2024 07:03:21 +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 1rmTVH-00ALty-TU for pgsql-general@lists.postgresql.org; Tue, 19 Mar 2024 07:03:20 +0000 Received: from mail-oi1-x235.google.com ([2607:f8b0:4864:20::235]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rmTV2-005HB0-A0 for pgsql-general@lists.postgresql.org; Tue, 19 Mar 2024 07:03:14 +0000 Received: by mail-oi1-x235.google.com with SMTP id 5614622812f47-3bbbc6b4ed1so3963933b6e.2 for ; Tue, 19 Mar 2024 00:03:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fincuro-com.20230601.gappssmtp.com; s=20230601; t=1710831779; x=1711436579; darn=lists.postgresql.org; h=in-reply-to:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=TQbbOi7X6VCpSw1B28XjrDr1TkMIK9MlhalJrP1L9yA=; b=AggVhlRUZecO7CV1TueL8KkHMNIygTsNBWha3GMQ0faVglXlzMT4T+GwY2h/lwm/Ov ewnxAnfyN1QXLn3JWGIQjYOt9J1ftpPTeeLnnmDY83PlrEN7K6ydWrvAWvqtrreutLsT hhViEQz7PnG6XTdQAgCRoZn3Opk9YqBdYC45uwvMoftyimJiEIz9qiOiFa9pDhpHo55B oruGQAdVecGIcMIBGlFdVHZ+u12SscVXXsCRrgrVrX9/JmOCOGhjFu5+W059e2f4KavM tkpoyB5cEWymLWVSroVk28xkjWObxBdtVqpyvloySMhAPtnpr1Dp1LcXvhJZz7Mx6kKd TtJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710831779; x=1711436579; h=in-reply-to:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=TQbbOi7X6VCpSw1B28XjrDr1TkMIK9MlhalJrP1L9yA=; b=DjPycQqDPmVC60yH4pVm5ezuzZw3UJeBZjGa04dL3xe+gcM117oAu4nlSGAidSGIyb WLHVJ4i8KYvpiB6uc0itVYrcYE/G+bXlLaMw28YL37B2Bl8Ss0dNpEdbqvTZKf0Ae2+C gHK4EAm/mhE7F+5zEeeEONwMlYojW6gRIUArjmr0f7Ntv5mnGhbeZClBjnxHjLZ75d9x DeA8kceR0ST3HjP2ufPmVLV3SwVJFzjctrjA6qpJ4x595y0cUkrrlGej323S2wpwmkG3 TaNM5F/hHCsAlPRnuHa5H34EsMFqHTBMV0LGBPiVo2/h9te9NRg07gXEwNAxLFpQuDFC AYOw== X-Gm-Message-State: AOJu0Yye6YRfarCrbyUq8qquv8Hvvrq0orayNqV4CMLsIiNj21kvKeDv Q6UiSJLujl614TyEyfyRjv7gGobBrIX/zs+LDtbmqz11sjNhhsvAuFVvNj6wJHA= X-Google-Smtp-Source: AGHT+IFu5RORnks7QxqkV+v56xWpAf7GuP8vcpfOGE53M1iQKRW/gtFhYdYYvmFfMcY93HiA67BNKA== X-Received: by 2002:a05:6358:4041:b0:17b:8706:fd39 with SMTP id a1-20020a056358404100b0017b8706fd39mr20289331rwa.10.1710831779558; Tue, 19 Mar 2024 00:02:59 -0700 (PDT) Received: from [172.26.200.9] ([49.205.149.243]) by smtp.gmail.com with ESMTPSA id o14-20020a63fb0e000000b005cfc1015befsm8350411pgh.89.2024.03.19.00.02.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 Mar 2024 00:02:59 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------8DWF0or0cu9xuWhW2yGWMdKR" Message-ID: <51e46e31-b1d9-4b4c-8c2a-a3de93333f0b@fincuro.com> Date: Tue, 19 Mar 2024 12:32:54 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: operator is only a shell - Error Content-Language: en-US To: Adrian Klaver , Greg Sabino Mullane Cc: pgsql-general@lists.postgresql.org References: <7f97243d-db62-199a-8412-5637963d117e@fincuro.com> <5884c2c6-d46b-4ead-b089-2572848b02a1@fincuro.com> From: Rajesh S In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------8DWF0or0cu9xuWhW2yGWMdKR Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Sorry Adrian, my bad. I'd mentioned "deposit_sub_no='1'" by mistake, actually it was "deposit_sub_no=cast(1 as varchar)". This was throwing error "SQL Error [42883]: ERROR: operator does not exist: numeric = character varying  Hint: No operator matches the given name and argument types. You might need to add explicit type casts.  Position: 19".  Then realized that "numeric=text" works but "numeric=varchar" does not.  I could resolve the problem by creating the following function and operator by commenting "CUMMUTATOR" and "NEGATOR".  Also the error "operator is only a shell" also vanished.  I'm just sharing the script for your reference.  Thank you very much for your valuable support. CREATE OR REPLACE FUNCTION public.num_eq_varchar(     numeric,     varchar)     RETURNS boolean AS 'select case when $2 ~ ''^[0-9\.]+$'' then $1 operator(pg_catalog.=) cast($2 as numeric) else $1::varchar = $2 end;' LANGUAGE SQL IMMUTABLE; -- Operator: =; -- DROP OPERATOR IF EXISTS public.= (numeric , varchar); CREATE OPERATOR public.= (     FUNCTION = num_eq_varchar,     LEFTARG = numeric,     RIGHTARG = varchar, --     COMMUTATOR = =, --     NEGATOR = <>,     RESTRICT = eqsel,     JOIN = eqjoinsel,     HASHES, MERGES ); Thanks, Rajesh S On 18-03-2024 21:20, Adrian Klaver wrote: > On 3/18/24 00:05, Rajesh S wrote: >> Thank you for your response.  Actually, I was trying to address the >> following query. >> >> select LIEN_AC_NO from deposit_lien where deposit_no='0002114029832' >> and deposit_sub_no='1' and unlien_dt is null and unlien_remarks is null; >> >> In the above query "deposit_sub_no" column is "numeric" type and >> passing '1' (as varchar).  To address this I'd created the function >> and operator as I'd mentioned in the earlier mail. Even the following >> query throws error after creating the function and operator. >> >> select * from deposit_lien where deposit_no='0002114029832'; >> >> ERROR: operator is only a shell: character varying = numeric LINE 1: >> select * from deposit_lien where deposit_no='0002114029832' ^ SQL >> state: 42883 Character: 44 >> >> In the above query "deposit_no" column is having "varchar" data >> type.  But before creating the function and operator it was working >> fine.  Tried dropping the same, even though the same error.  How to >> proceed now? > > Not clear to me what the problem is you are trying to solve? > > On a stock Postgres install: > > select 1::numeric = '1'; >  ?column? > ---------- >  t > > select '0002114029832'::varchar = '0002114029832'; >  ?column? > ---------- >  t > > >> >> >> Thanks, >> >> Rajesh S >> >> On 15-03-2024 19:10, Greg Sabino Mullane wrote: >>> On Fri, Mar 15, 2024 at 6:26 AM Rajesh S wrote: >>> >>>     I wanted to implement a new "=" (equal) operator with LEFTARG as >>>     numeric and RIGHTARG as varchar.  But after creating the function >>>     and operator, psql shows the error "operator is only a shell: >>>     character varying = numeric >>> >>> Your operator has numeric on the left and varchar on the right. But >>> your query is doing numeric on the RIGHT. Probably want to make a >>> matching one to cover both cases. >>> >>> Cheers, >>> Greg >>> > --------------8DWF0or0cu9xuWhW2yGWMdKR Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

Sorry Adrian, my bad. I'd mentioned "deposit_sub_no=3D'1'" by mistake, actually it was "deposit_sub_no=3Dcast(1 as varchar)".=C2=A0= This was throwing error "SQL Error [42883]: ERROR: operator does not exist: numeric =3D character varying=C2=A0 Hint: No operator ma= tches the given name and argument types. You might need to add explicit type casts.=C2=A0 Position: 19".=C2=A0 Then realized that "numeric=3D= text" works but "numeric=3Dvarchar" does not.=C2=A0 I could resolve the p= roblem by creating the following function and operator by commenting "CUMMUTATOR" and "NEGATOR".=C2=A0 Also the error "operator is only = a shell" also vanished.=C2=A0 I'm just sharing the script for your reference.=C2=A0 Thank you very much for your valuable support.

CREATE OR REPLACE FUNCTION public.num_eq_varchar(
=C2=A0=C2=A0 =C2=A0numeric,
=C2=A0=C2=A0 =C2=A0varchar)
=C2=A0=C2=A0=C2=A0 RETURNS boolean
AS 'select case when $2 ~ ''^[0-9\.]+$'' then $1 operator(pg_catalog.=3D) cast($2 as numeric) else $1::varchar =3D= $2 end;'
LANGUAGE SQL IMMUTABLE;

-- Operator: =3D;

-- DROP OPERATOR IF EXISTS public.=3D (numeric , varchar);

CREATE OPERATOR public.=3D (
=C2=A0=C2=A0=C2=A0 FUNCTION =3D num_eq_varchar,
=C2=A0=C2=A0=C2=A0 LEFTARG =3D numeric,
=C2=A0=C2=A0=C2=A0 RIGHTARG =3D varchar,
--=C2=A0=C2=A0=C2=A0=C2=A0 COMMUTATOR =3D =3D,
--=C2=A0=C2=A0=C2=A0=C2=A0 NEGATOR =3D <>,
=C2=A0=C2=A0=C2=A0 RESTRICT =3D eqsel,
=C2=A0=C2=A0=C2=A0 JOIN =3D eqjoinsel,
=C2=A0=C2=A0=C2=A0 HASHES, MERGES
);


Thanks,

Rajesh S

=C2=A0

=C2=A0

On 18-03-2024 21:20, Adrian Klaver wrote:
On 3/18/24 00:05, Rajesh S wrote:
Thank you for your response.=C2=A0 Actual= ly, I was trying to address the following query.

select LIEN_AC_NO from deposit_lien where deposit_no=3D'0002114029832' and deposit_sub_no=3D'1' and unlien_= dt is null and unlien_remarks is null;

In the above query "deposit_sub_no" column is "numeric" type and passing '1' (as varchar).=C2=A0 To address this I'd created the function and operator as I'd mentioned in the earlier mail.=C2=A0= Even the following query throws error after creating the function and operator.

select * from deposit_lien where deposit_no=3D'0002114029832';

ERROR: operator is only a shell: character varying =3D numeric LINE 1: select * from deposit_lien where deposit_no=3D'0002114029832' ^ SQL state: 42883 Character: 44

In the above query "deposit_no" column is having "varchar" data type.=C2=A0 But before creating the function and operator it was working fine.=C2=A0 Tried dropping the same, even though the same= error.=C2=A0 How to proceed now?

Not clear to me what the problem is you are trying to solve?

On a stock Postgres install:

select 1::numeric =3D '1';
=C2=A0?column?
----------
=C2=A0t

select '0002114029832'::varchar =3D '0002114029832';
=C2=A0?column?
----------
=C2=A0t




Thanks,

Rajesh S

On 15-03-2024 19:10, Greg Sabino Mullane wrote:
On Fri, Mar 15, 2024 at 6:26=E2=80=AFAM= Rajesh S <rajesh.s@fincuro.com> wrote:

=C2=A0=C2=A0=C2=A0 I wanted to implement a new "=3D" (equal) op= erator with LEFTARG as
=C2=A0=C2=A0=C2=A0 numeric and RIGHTARG as varchar.=C2=A0 But a= fter creating the function
=C2=A0=C2=A0=C2=A0 and operator, psql shows the error "operator= is only a shell:
=C2=A0=C2=A0=C2=A0 character varying =3D numeric

Your operator has numeric on the left and varchar on the right. But your query is doing numeric on the RIGHT. Probably want to make a matching one to cover both cases.

Cheers,
Greg


--------------8DWF0or0cu9xuWhW2yGWMdKR--