如何在 PostgreSQL 中定义运算符别名?
有没有一种简单的方法可以在 PostgreSQL 中为 =
运算符定义运算符别名?
对于 !=
和 <>
运算符来说,这个问题是如何解决的? pg_operators 中似乎只有 <>
运算符。 !=
运算符是硬编码的吗?
这对于使用自定义运算符的应用程序是必需的。在大多数环境中,此运算符的行为应类似于 =
,但在某些情况下,我们通过创建自己的运算符和运算符类来定义特殊行为。但对于正常情况,我们的运算符应该只是 =
运算符的别名,这样对于使用哪个实现的应用程序来说是透明的。
Is there an easy way to define an operator alias for the =
operator in PostgreSQL?
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需检查 pgAdmin,模式 pg_catalog。它包含所有运算符,并向您展示如何为所有数据类型创建它们。是的,您必须为所有数据类型创建它们。所以这不仅仅是一个“别名”,你需要很多别名。
char = char 的示例,使用!!!!作为别名:
同时查看手册并注意对于命名规则来说,它有一些限制。
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:
Check the manual as well and pay attention to the naming rules, it has some restrictions.