瀚高資料庫自定義操作符'!~~'

瀚高PG實驗室發表於2022-06-21
環境
系統平臺: Microsoft Windows (64-bit) 10
版本: 5.6.5
詳細資訊

一,測試準備

建立表並插入資料:

create TABLE oper_test(first_num int);
insert into oper_test values(234),(446),(467);

二,測試查詢

select (446 !~~  first_num) newlist from oper_test;

image.png

三,解決方案:自定義操作符

CREATE OR REPLACE FUNCTION hgdb_catalog.intnlike(integer,integer)
  RETURNS boolean AS $$
  select $1::varchar !~~ $2::varchar;
  $$
  LANGUAGE sql strict;
ALTER FUNCTION intnlike(integer, integer)
  OWNER TO highgo;
COMMENT ON FUNCTION intnlike(integer,integer) IS 'implementation of !~~ operator';
create operator hgdb_catalog.!~~(
    procedure = hgdb_catalog.intnlike,
    leftarg = integer,
    rightarg = integer
);

四,再次查詢

image.png



來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69994931/viewspace-2901926/,如需轉載,請註明出處,否則將追究法律責任。

相關文章