title: How to execute delete statement inside a function
body: <p>I want clients of my application to call <code>DELETE</code> statements indirectly or using a function. This is what I tried:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION layer_250_delete(layer_id integer)
      RETURNS bool AS
  $BODY$ 
  BEGIN    
      EXECUTE 'DELETE FROM layer_250_ WHERE id = $1' USING layer_id;    
      RETURN TRUE;   
  END; 
  $BODY$
     LANGUAGE plpgsql VOLATILE
     COST 100;
  ALTER FUNCTION layer_250_delete(integer)
  OWNER TO postgres;
  </code></pre>
  
  <p>I also tried a raw query:</p>
  
  <pre><code>...
  DELETE FROM layer_250_ WHERE id = 1';    
  RETURN TRUE;
  ...
  </code></pre>
  
  <p>However, when I call this function (variant 1 or 2) like this:</p>
  
  <pre><code>select layer_250_delete(1);
  </code></pre>
  
  <p>it does not delete a row from <code>layer_250_</code> table. I scanned dozens of threads here at stackoverflow, but could not find anything similar to my task.</p>
  
  <p><strong>STRUCTURE</strong></p>
  
  <pre><code>CREATE TABLE public.layer_250_
  (
    id integer NOT NULL DEFAULT nextval('layer_250__id_seq'::regclass),
    feature_type character varying(100) NOT NULL,
    feature_hash character varying(500) NOT NULL,
    feature_uid character varying(100) NOT NULL,
    geom geometry,
    radius integer,
    group_id integer,
    object_id integer NOT NULL DEFAULT 0,
    row_id integer NOT NULL DEFAULT 0,
    action_time timestamp without time zone NOT NULL DEFAULT now(),
    action_type character varying(255),
    action_user_id integer,
    action_user_ip character varying(255),
    CONSTRAINT layer_250__pkey PRIMARY KEY (id),
    CONSTRAINT layer_250__feature_uid_key UNIQUE (feature_uid),
    CONSTRAINT enforce_dims_geom_layer_250_ CHECK (st_ndims(geom) = 2),
    CONSTRAINT enforce_srid_geom_layer_250_ CHECK (st_srid(geom) = 3857)
  )
  WITH (
    OIDS=FALSE
  );
  ALTER TABLE public.layer_250_
    OWNER TO postgres;
  </code></pre>