The CREATE INDEX command contains a function which has at least one SQL command. This is not allowed.
Remove the SQL commands from the function.