English 中文(简体)
PostgreSQL 有条件触发
原标题:PostgreSQL trigger with a condition

在MyBatis地图上,

    <select id="selectValues" parameterType= int  resultType="SomeType">
        select foo from bar where baz=#{qux}
    </select>

可以从表格中返回 SomeType 值列表。 但是, 如果返回的列表是空的, 如果是空的, 则给它一个无效的值, 我愿意使用触发符来检查 。 它可能看起来像 :

CREATE TRIGGER mytrigger AFTER select ON bar FOR EACH STATEMENT EXECUTE PROCEDURE trigger_after_select ();

CREATE FUNCTION trigger_after_select () RETURNS trigger AS   
BEGIN 
if (select count(*) from bar)=0
then return NULL; 
...

我怀疑我是否朝着正确的方向前进,是否有人能告诉我其他触发器会是什么样子(如果起点看起来合适的话 ) 。 提供建议会有所帮助,多亏了建议。

最佳回答

Postgres没有“ SELECT” 触发器。

如果您将 SQL 更改为 :

select foo from bar where baz=#{qux}
union all
select null where not exists (select 1 from bar where baz=#{qux})

然后,您将获得相同的效果。如果列 < code> baz 没有带有该值的行, 它将返回 NULL 值 。

(Disamer:我不知道MyBatis, 所以我不知道能否具体说明这样的声明)

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签