title: PostgreSQL Declared Variable in Function
body: <p>I work with Potgresql and I have written function</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION staging.shape_commit(layer_id integer)
    RETURNS integer AS
  $BODY$
  declare     
    layer_name text;
  
  begin
  layer_name:=(select shape.layer_name from staging.shape where shape.id=layer_id);
  delete  from layer_name;
  return layer_name;
  end;
  $BODY$
    LANGUAGE plpgsql VOLATILE
    COST 100;
  ALTER FUNCTION staging.shape_commit(integer)
    OWNER TO test;
  </code></pre>
  
  <p>layer_name is variable and really it is table name .but script ignore it as variable and uses as string </p>
  
  <p>Cam anybody help me?</p>