How to access data inside a "before insert trigger" for every statement
The doc for CREATE TRIGGER in PostgreSQL 10 says:


  Triggers that are specified to fire INSTEAD OF the trigger event must
  be marked FOR EACH ROW, and can only be defined on views


Assuming nvme_ts is a view, you're trying to define a FOR EACH STATEMENT trigger in a case that the doc explicitly disallows.

Besides, the code shown in create_ts_partition() is meant for a single row, not for multiple rows with potentially different years.
You probably simply need for a FOR EACH ROW trigger, if you're set on using a trigger at all to manage the partitions.