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 1rl4lH-00HTbE-T5 for pgsql-general@arkaria.postgresql.org; Fri, 15 Mar 2024 10:26:04 +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 1rl4lE-007p7y-Mz for pgsql-general@arkaria.postgresql.org; Fri, 15 Mar 2024 10:26:01 +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 1rl4lD-007p7q-RH for pgsql-general@lists.postgresql.org; Fri, 15 Mar 2024 10:26:00 +0000 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rl4l5-004cw0-2j for pgsql-general@lists.postgresql.org; Fri, 15 Mar 2024 10:25:58 +0000 Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-53fa455cd94so1523233a12.2 for ; Fri, 15 Mar 2024 03:25:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fincuro-com.20230601.gappssmtp.com; s=20230601; t=1710498350; x=1711103150; darn=lists.postgresql.org; h=in-reply-to:references:to:from:content-language:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=PRSDplfxniyR+mhRtPxSpZHECz5OolhgFFG7auVXxwI=; b=byZuJibwhNh0g61hhvon2IvzrHS6ZuseQ5ZlEI8ZsJqlf+gcK01Y/JJcfBDjFBpOQx /7tTAUpAYH1ITzTYlOUl9tHsbLgWWnQM4Gh4Lb2p+HFjDRTpNEywLdNtwEbC8uqZTRLc Xi6mwehhepLyPZXtmEFVWfrEI06rt56Cc7l++b1R62By1wLciW3DL5KUcogYIq7lx8gE e7NepVKSRAzNfEPbM7RLmAXkhv6ndUXimpOIW74+UOvOp2chpZBfTJAt3SZ16m/qi09t nBvjuV1TJAhqxEaDHjV+C458emHEvcNCF+5TSXpa30a+R+3MP13lNCMOAje1Ku2Da59c ZoUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710498350; x=1711103150; h=in-reply-to:references:to:from:content-language:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=PRSDplfxniyR+mhRtPxSpZHECz5OolhgFFG7auVXxwI=; b=Roj/VmFDycvJCjvMJokQlzWRBB35FQcMO9mlqM0cu9BpimbhSXBr6EjA0CVXC9H9GZ 97DEYCCKhqqBVLBqTeoa4lZ4731aNmuRxVe2w4YKENe9uLLmXAuVxEphQumAwKcz9Dm9 lmIeyJJA8EmgIJlewC4jTjY/hlaM9xI8Qf1+d6VEByGrNXoFnFU8WtWAgANv8wBwhYRI kEMmIre/RztuSPLsKZJlo4cO2n5lejzeusp5SZolRA8Gt0y/if9una50Wq6gMNBwxVxU v1fSXtj1vLxWh1osaJhLndyWlbLpK9dGMrNOae39etuxkYh49GPxheJeHWziIaift8hP k6PA== X-Gm-Message-State: AOJu0YxKZ5d6u7XNKYDicNrrO7HzJSNj/TOMgshMCkessH73zgz1NLrj 4X1fTQy2QpwtXZ06YjybR7VjhEbWoAtKBsxBntPWOWmXFcvjJVcyKJ6DMBt21PzEGumyZiLxvRP 5JjqbtQ== X-Google-Smtp-Source: AGHT+IHddvq+E9Bnn0ra9E2Qv6BBF95N68AM4WAydX+5EPzsOh9XpmCRylc4XDFE59EmtV0jjmclbg== X-Received: by 2002:a17:90a:17a3:b0:29b:4a20:18b7 with SMTP id q32-20020a17090a17a300b0029b4a2018b7mr4173290pja.8.1710498350120; Fri, 15 Mar 2024 03:25:50 -0700 (PDT) Received: from [172.26.200.9] ([49.205.149.243]) by smtp.gmail.com with ESMTPSA id cz14-20020a17090ad44e00b0029becfcb97esm2570912pjb.22.2024.03.15.03.25.48 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 15 Mar 2024 03:25:49 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------c4lvjAxn0Na0taZFHQmueRDZ" Message-ID: Date: Fri, 15 Mar 2024 15:55:45 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: operator is only a shell - Error Content-Language: en-US From: Rajesh S To: pgsql-general@lists.postgresql.org References: <7f97243d-db62-199a-8412-5637963d117e@fincuro.com> In-Reply-To: <7f97243d-db62-199a-8412-5637963d117e@fincuro.com> 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. --------------c4lvjAxn0Na0taZFHQmueRDZ Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi, 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 LINE 1: ...lect LIEN_AC_NO from deposit_lien where deposit_no='00021140...". I'm sharing the function and operator scripts for your perusal. Please advise how to proceed. CREATE OR REPLACE FUNCTION public.num_eq_varchar(     numeric,     varchar)     RETURNS boolean AS 'select $1::NUMERIC=CAST($2 AS numeric);' 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 ); CREATE OR REPLACE FUNCTION public.num_ne_varchar(     numeric,     varchar)     RETURNS boolean     LANGUAGE SQL IMMUTABLE AS $BODY$     select $1<>$2::numeric; $BODY$; -- Operator: <>; -- DROP OPERATOR IF EXISTS public.<> (numeric , varchar); CREATE OPERATOR public.<> (     FUNCTION = num_ne_varchar,     LEFTARG = numeric,     RIGHTARG = varchar,     COMMUTATOR = <>,     NEGATOR = =,     RESTRICT = neqsel,     JOIN = neqjoinsel ); Thanks, Rajesh S On 05-07-2022 13:52, Rajesh S wrote: > > Hi, > > We are migrating our database from Oracle to Postgresql.  In oracle we > have used this syntax "SELECT ('1999-12-30'::DATE) - > ('1999-12-11'::DATE)" to get difference between two dates as a integer > output (ex: 19).  But in Postgres the same query returns result as "19 > days".  Because of this we are getting errors while assigning this > query output to a numeric variable saying "ERROR: invalid input syntax > for type numeric: "1825 days"" and "ERROR: operator does not exist: > interval + integer".  To avoid changing the application code in many > places to extract the number of days alone, we tried operator > overloading concept as below. > > CREATE OR REPLACE FUNCTION public.dt_minus_dt( >     dt1 timestamp without time zone, >     dt2 timestamp without time zone) >     RETURNS integer >     LANGUAGE 'edbspl' >     COST 100 >     VOLATILE SECURITY DEFINER PARALLEL UNSAFE > AS $BODY$ >     days INTEGER; > BEGIN >     SELECT DATE_PART('day', dt1::timestamp - dt2::timestamp)::integer > INTO days; >     RETURN days; > END > $BODY$; > > CREATE OPERATOR public.- ( >     FUNCTION = public.dt_minus_dt, >     LEFTARG = timestamp without time zone, >     RIGHTARG = timestamp without time zone > ); > > When we execute "SELECT ('1999-12-30'::DATE) - ('1999-12-11'::DATE)", > we are still getting "19 days" as result and not "19" as we expect.  > The above same function works as expected for the operator + or ===. > > CREATE OPERATOR public.+ ( >     FUNCTION = public.dt_minus_dt, >     LEFTARG = timestamp without time zone, >     RIGHTARG = timestamp without time zone > ); > > SELECT ('1999-12-30'::DATE) + ('1999-12-11'::DATE) > > CREATE OPERATOR public.=== ( >     FUNCTION = public.dt_minus_dt, >     LEFTARG = timestamp without time zone, >     RIGHTARG = timestamp without time zone > ); > > SELECT ('1999-12-30'::DATE) === ('1999-12-11'::DATE) > > > I really appreciate anyone's help in resolving this case. Thanks in > advance. > > > Rajesh S > > --------------c4lvjAxn0Na0taZFHQmueRDZ Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

Hi,

I wanted to implement a new "=3D" (equal) operator with LEFTARG as= numeric and RIGHTARG as varchar.=C2=A0 But after creating the funct= ion and operator, psql shows the error "operator is only a shell: character varying =3D numeric LINE 1: ...lect LIEN_AC_NO from deposit_lien where deposit_no=3D'0002114= 0...".=C2=A0=C2=A0 I'm sharing the function and operator scripts for your perusal.=C2=A0= Please advise how to proceed.

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 $1::NUMERIC=3DCAST($2 AS numeric);'
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 COMMUTATOR =3D =3D,
=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
);

CREATE OR REPLACE FUNCTION public.num_ne_varchar(
=C2=A0=C2=A0 =C2=A0numeric,
=C2=A0=C2=A0 =C2=A0varchar)
=C2=A0=C2=A0=C2=A0 RETURNS boolean
=C2=A0=C2=A0=C2=A0 LANGUAGE SQL IMMUTABLE
AS $BODY$
=C2=A0=C2=A0 =C2=A0select $1<>$2::numeric;
$BODY$;

-- Operator: <>;

-- DROP OPERATOR IF EXISTS public.<> (numeric , varchar);
=
CREATE OPERATOR public.<> (
=C2=A0=C2=A0=C2=A0 FUNCTION =3D num_ne_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 COMMUTATOR =3D <>,
=C2=A0=C2=A0=C2=A0 NEGATOR =3D =3D,
=C2=A0=C2=A0=C2=A0 RESTRICT =3D neqsel,
=C2=A0=C2=A0=C2=A0 JOIN =3D neqjoinsel
);


Thanks,

Rajesh S

=C2=A0

=C2=A0

On 05-07-2022 13:52, Rajesh S wrote:

Hi,

We are migrating our database from Oracle to Postgresql.=C2=A0 I= n oracle we have used this syntax "SELECT ('1999-12-30'::DATE) - ('1999-12-11'::DATE)" to get difference between two dates as a integer output (ex: 19).=C2=A0 But in Postgres the same query ret= urns result as "19 days".=C2=A0 Because of this we are getting errors while assigning this query output to a numeric variable saying "ERROR: invalid input syntax for type numeric: "1825 days"" and "ERROR: operator does not exist: interval + integer".=C2=A0 To av= oid changing the application code in many places to extract the number of days alone, we tried operator overloading concept as below.

CREATE OR REPLACE FUNCTION public.dt_minus_dt(
=C2=A0=C2=A0 =C2=A0dt1 timestamp without time zone,
=C2=A0=C2=A0 =C2=A0dt2 timestamp without time zone)
=C2=A0=C2=A0=C2=A0 RETURNS integer
=C2=A0=C2=A0=C2=A0 LANGUAGE 'edbspl'
=C2=A0=C2=A0=C2=A0 COST 100
=C2=A0=C2=A0=C2=A0 VOLATILE SECURITY DEFINER PARALLEL UNSAFE
AS $BODY$
=C2=A0=C2=A0=C2=A0 days INTEGER;
BEGIN
=C2=A0=C2=A0=C2=A0 SELECT DATE_PART('day', dt1::timestamp - dt2::timestamp)::integer INTO days;
=C2=A0=C2=A0=C2=A0 RETURN days;
END
$BODY$;

CREATE OPERATOR public.- (
=C2=A0=C2=A0=C2=A0 FUNCTION =3D public.dt_minus_dt,
=C2=A0=C2=A0=C2=A0 LEFTARG =3D timestamp without time zone,
=C2=A0=C2=A0=C2=A0 RIGHTARG =3D timestamp without time zone
);

When we execute "SELECT ('1999-12-30'::DATE) - ('1999-12-11'::DATE)", we are still getting "19 days" as result and not "19" as we expect.=C2=A0 The above same function works as= expected for the operator + or =3D=3D=3D.=C2=A0

CREATE OPERATOR public.+ (
=C2=A0=C2=A0=C2=A0 FUNCTION =3D public.dt_minus_dt,
=C2=A0=C2=A0=C2=A0 LEFTARG =3D timestamp without time zone,
=C2=A0=C2=A0=C2=A0 RIGHTARG =3D timestamp without time zone
);

SELECT ('1999-12-30'::DATE) + ('1999-12-11'::DATE)

CREATE OPERATOR public.=3D=3D=3D (
=C2=A0=C2=A0=C2=A0 FUNCTION =3D public.dt_minus_dt,
=C2=A0=C2=A0=C2=A0 LEFTARG =3D timestamp without time zone,
=C2=A0=C2=A0=C2=A0 RIGHTARG =3D timestamp without time zone
);

SELECT ('1999-12-30'::DATE) =3D=3D=3D ('1999-12-11'::DATE)


I really appreciate anyone's help in resolving this case.=C2=A0 Thanks in advance.


Rajesh S


=
=
--------------c4lvjAxn0Na0taZFHQmueRDZ--