如何在PostgreSQL中定义操作符别名? [英] How to define an operator alias in PostgreSQL?

查看:1022
本文介绍了如何在PostgreSQL中定义操作符别名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个简单的方法来为PostgreSQL中的 = 运算符定义运算符别名?

Is there an easy way to define an operator alias for the = operator in PostgreSQL?

解决了!= <> 运算符?只有<> 运算符似乎在pg_operators中。是!= 运算符是否硬编码?

How is that solved for the != and <> operator? Only the <> operator seems to be in pg_operators. Is the != operator hard-coded?

这是使用自定义运算符。在大多数环境中,这个操作符应该像 = ,但是在某些情况下,我们通过创建一个自己的操作符和操作符类来定义一个特殊的行为。但对于正常情况,我们的运算符应该只是 = 运算符的别名,因此对于使用该实现的应用程序是透明的。

This is needed for an application which uses a self-defined operator. In most environments this operator should act like a =, but there are some cases where we define a special behavior by creating an own operator and operator class. But for the normal case our operator should just be an alias for the = operator, so that it is transparent to the application which implementation is used.

推荐答案

只需检查pgAdmin,模式pg_catalog。它有所有的操作符,并告诉你如何为所有数据类型创建它们。是的,您必须为所有数据类型创建它们。所以它不只是一个单一的别名,你需要很多的aliasses。

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.

一个char = char的例子,使用!作为别名:

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.

这篇关于如何在PostgreSQL中定义操作符别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆