Extract last_insert_grn_id() code into udf/