Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I need a trigger to cause a reindex (index is on an immutable function) I define the function as

CREATE FUNCTION "TEST".triggerFuncTest()
RETURNS TRIGGER
AS $$
BEGIN
  REINDEX INDEX "TEST"."MyIndex";
  RETURN NULL;
END $$ LANGUAGE plpgsql;

with the trigger

CREATE CONSTRAINT TRIGGER triggerTest
AFTER INSERT OR UPDATE OF indexes OR DELETE ON "TEST"."MyTable"
DEFERRABLE INITIALLY DEFERRED
FOR EACH STATEMENT
EXECUTE PROCEDURE "TEST".triggerFuncTest();

Which gives

ERROR:  syntax error at or near "STATEMENT"

However the trigger will be created if I remove CONSTRAINT and DEFERRABLE INITIALLY DEFERRED, however this will cause an exception when triggered.

share|improve this question
1  
Why would you want to rebuild the index for each DML statement you are running? Are you aware that Postgres will automatically update the index? But a constraint trigger is the wrong thing in the first place, you want to a regular trigger (but still: this does not make any sense) – a_horse_with_no_name Jan 7 at 13:41
    
indexes on an immutable function dont get updated unfortunately – J Pullar Jan 7 at 13:42
    
And why are you defining an index on an immutable function? That doesn't make sense either. – a_horse_with_no_name Jan 7 at 13:43
    
Also I tried a regular trigger, it throws an error as you cant change a tables index whilst its being accessed in the transaction – J Pullar Jan 7 at 13:44
    
The reason for the index on the immutable function is here stackoverflow.com/questions/34655425/… – J Pullar Jan 7 at 13:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.