How to define an operator alias in PostgreSQL?

不打扰是莪最后的温柔 提交于 2019-12-02 02:14:25

Just check pgAdmin, the schema pg_catalog. It has all the operators and show you how the create them for all datatypes. Yes, you have to create them for all datatypes. So it's not just a single "alias", you need a lot of aliasses.

Example for a char = char, using !!!! as the alias:

CREATE OPERATOR !!!!   -- name
(
  PROCEDURE = pg_catalog.chareq,
  LEFTARG = "char",
  RIGHTARG = "char",
  COMMUTATOR = !!!!, -- the same as the name
  RESTRICT = eqsel,
  JOIN = eqjoinsel,
  HASHES,
  MERGES
);
SELECT 'a' !!!! 'a' -- true
SELECT 'a' !!!! 'b' -- false

Check the manual as well and pay attention to the naming rules, it has some restrictions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!