Re: operator is only a shell - Error

From: Greg Sabino Mullane <htamfids(at)gmail(dot)com>
To: Rajesh S <rajesh(dot)s(at)fincuro(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: operator is only a shell - Error
Date: 2024-03-18 14:47:43
Message-ID: CAKAnmm+K+CHnP3nxd1nSzRnCWcvAw7WqkYna5hmhMYyGxLQk3A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

The order of the arguments matter. You need an operator that expects a
varchar on the left hand side of the operator, and numeric on the right
side. For example:

create database cast_test;
\c cast_test
You are now connected to database "cast_test" as user "greg".

cast_test=# create table deposit_lien(deposit_no varchar);
CREATE TABLE

cast_test=# select * from deposit_lien where
deposit_no='0002114029832'::numeric;
ERROR: operator does not exist: character varying = numeric

cast_test=# create function varchar_eq_numeric(varchar,numeric)
cast_test-# returns bool language sql immutable as $$ select
$1::numeric=$2::numeric $$;
CREATE FUNCTION

cast_test=# create operator public.= (function = varchar_eq_numeric,leftarg
= varchar,rightarg = numeric);
CREATE OPERATOR

cast_test=# select * from deposit_lien where
deposit_no='0002114029832'::numeric;
deposit_no
------------
(0 rows)

But before creating the function and operator it was working fine

Was it? It helps to show us the exact things ran and the exact output,
rather than just "it was working fine" :)

Cheers,
Greg

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2024-03-18 15:50:11 Re: operator is only a shell - Error
Previous Message Marc Millas 2024-03-18 12:30:37 ldap fdw