Say, I have the following in MyBatis mapper for a postgres table:
<select id="selectValues" parameterType='int' resultType="SomeType">
select foo from bar where baz=#{qux}
</select>
A list of SomeType values can be returned from the table. But I'd like to check with a help of trigger, if the returned list is empty and, if so, give it a null value. It would probably look like:
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;
...
I wonder if I'm moving in the right direction and if someone could tell how the rest of the trigger would look like (if the beginning looks suitable). An advice would be helpful, thanks in advice.