什么叫黑洞? [英] What's the equivalent of blackhole?

查看:144
本文介绍了什么叫黑洞?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用postgreSQL (最新)启动一个新项目,该项目已经使用MySQL 5.5一段时间了.

I'm starting a new project in postgreSQL (lastest) having worked with MySQL 5.5 for a while.

过去,我大量使用blackhole表来简化应用程序代码.
它允许我在应用程序代码中进行一次插入:

In the past I've made heavy use of blackhole table to simplify my application code.
It allows me to do one insert in application code:

INSERT INTO blackhole1 (val1, val2, val3, val4 ...

CREATE TRIGGER ai_blackhole1_each AFTER INSERT ....
BEGIN
  INSERT INTO table1 (....
  INSERT INTO table2 (....
  INSERT INTO log (.....

在黑洞表中有一个触发器,将值插入到不同的表中.

And have a trigger in the blackhole table insert the values into different tables.

我在postgreSQL中使用什么替换该功能?

我知道我可以使用存储过程,但这意味着我无法将数据感知控件连接到
黑洞表.因此,我希望该棒尽可能靠近MySQL原始版本.

I know I can use a stored procedure, but that means that I cannot connect data-aware controls to a
blackhole-table. So I would love the stick as close to the MySQL original as possible.

推荐答案

使用PostgreSQL 9.1,您可以创建触发器,就像使用MySQL一样.请注意,无法在9.1之前的版本中的视图上创建触发器.

With PostgreSQL 9.1 you can create triggers the same way you can do it with MySQL. Note that it is not possible to create triggers on views in versions before 9.1.

您是在MySQL的 blackhole 表中使用存储引擎BLACKHOLE还是仅仅是一个名称? PostgreSQL中没有可插拔的存储引擎,但是您可以获得与MySQL中的存储引擎BLACKHOLE相同的行为,在PostgreSQL的视图上使用INSTEAD OF触发器.我不太了解您对 data-aware 控件的看法:afaik,您在BLACKHOLE表(存储引擎)中没有任何 data-awareness ,但是在另一方面,你当然可以例如将休眠实体映射到数据库视图.

Do you use storage engine BLACKHOLE for your blackhole tables in MySQL or is it just a name? There are no pluggable storage engines in PostgreSQL, but you can get the same behavior as with storage engine BLACKHOLE in MySQL with INSTEAD OF triggers on a view in PostgreSQL. I don't quite get your point concerning data-aware controls: afaik you don't have any data-awareness in a BLACKHOLE table (the storage engine), but on the other hand you can of course e.g. map a hibernate entity to a database view.

使用触发器简化应用程序代码是好是坏决定取决于实际用例.例如,我更喜欢触发器而不是应用程序逻辑来进行日志记录和审计,因为这种方法为连接到数据库的不同应用程序以及管理员的临时查询/语句提供了一个单一的解决方案.但是根据我的经验,触发器不会消除复杂性,而只是将其转移到数据库层.这通常会使多层应用程序更难扩展和维护.

Whether it is a good or bad idea to use triggers to simplify application code depends on the actual use case. For example I prefer triggers over application logic for logging and auditing, because this approach offers a single solution for different applications connecting to the database as well as for ad hoc queries/statements by an administrator. But from my experience triggers do not remove complexity but just shift it to the database layer. This generally makes a multi-layered application harder to extend and maintain.

这篇关于什么叫黑洞?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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