Postgres: how to tell if insert took place
Try this

 CREATE OR REPLACE FUNCTION mysp() RETURNS integer AS
 $BODY$
 DECLARE
 aff_rows numeric;
 BEGIN
     execute 'INSERT INTO mytable (locationname) VALUES (''some text'') WHERE NOT EXISTS (SELECT 1 FROM mytable WHERE locationname=''some text'')';
     GET DIAGNOSTICS aff_rows = ROW_COUNT;
     raise info 'affected rows :: %', aff_rows;
     return aff_rows;
 END
 $BODY$
 LANGUAGE 'plpgsql' ;


Source: https://www.postgresql.org/docs/current/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-DIAGNOSTICS

(refer section: 39.5.5. Obtaining the Result Status)