DDL Partitionion Inheritance -- improved trigger function
От | Kirk Parker |
---|---|
Тема | DDL Partitionion Inheritance -- improved trigger function |
Дата | |
Msg-id | CANwZ8rkXSFCBOXW8mZ37vYo_MUe-Q35AOTX8uEjEZ2sRwqRohw@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: DDL Partitionion Inheritance -- improved trigger function
|
Список | pgsql-docs |
I'm a big fan of maintenance-free functions. What would you think about adding the following as an alternative trigger function, or as a replacement for the current function, to
https://www.postgresql.org/docs/current/ddl-partitioning.html#DDL-PARTITIONING-INHERITANCE-EXAMPLE , item #5? For the modest overhead of an extra call to to_char() and using EXECUTE rather than a literal INSERT, you get a trigger function that works forever. Given that the example anticipates one insert per city/day, it doesn't expect an extremely high rate of inserts where every microsecond counts.CREATE OR REPLACE FUNCTION measurement_insert_trigger()RETURNS TRIGGER AS $$BEGINEXECUTE format('INSERT INTO measurement_%s VALUES (NEW.*)', to_char( NEW.logdate, 'YYYYMM'));RETURN NULL;END;$$LANGUAGE plpgsql;
And yes, bad things happen if the partition table does not exist, but that's true of the other trigger functions shown here, too.
В списке pgsql-docs по дате отправления: