title: Call Postgres SQL stored procedure From Django
body: <p>I am working on a Django Project with a Postgres SQL Database. I have written a stored procedure that runs perfectly on Postgres.</p>
  
  <p>Now I want to call that stored procedure from Django 1.5 .. I have written the code but it prompts errors.</p>
  
  <pre><code>CREATE FUNCTION fn_save_message3(IN msg_sub character varying, IN msg_cont text, IN msg_type character varying, IN msg_category character varying, IN msg_created_by character varying, IN msg_updated_by character varying) RETURNS integer AS
  $BODY$ DECLARE msg_id integer := 0;
  BEGIN
      INSERT INTO tbl_messages
          (message_subject, message_content, message_type, message_category, 
         created_on, created_by, updated_on, updated_by)
      VALUES 
        (msg_sub, msg_cont, msg_type, msg_category, LOCALTIMESTAMP, 
         msg_created_by, LOCALTIMESTAMP, msg_updated_by);
        Select into msg_id currval('tbl_messages_message_id_seq');
    return msg_id;
  END;$BODY$
  LANGUAGE plpgsql VOLATILE NOT LEAKPROOF
  COST 100;
  ALTER FUNCTION public.fn_save_message(IN character varying, IN text, IN character varying, IN character varying, IN character varying, IN character varying)
    OWNER TO gljsxdlvpgfvui;
  </code></pre>
  
  <p>The Stored Procedure is Ok and it returns results.</p>
  
  <pre><code>c = connection.cursor()
      try:
          c.execute("BEGIN")
          c.callproc("fn_save_message", [Message_Subject, Message_Content, Message_Type, Message_Category, Created_By, updated_by])
          results = c.fetchone()
          c.execute("COMMIT")
      finally:
          c.close()
      print results
  </code></pre>
  
  <p>After all your suggestion my program is finally working. but one small issue left.</p>
  
  <p>As i have used <code>results = c.fetchone()</code> to fetch the out parameters. 
  it returns <strong>(13,)</strong></p>
  
  <p>but I only want to get <strong>13</strong> as a string or integer, how can I get only the value.</p>
  
  <p><strong>Updated:</strong></p>
  
  <p>the problem is solved using this</p>
  
  <pre><code>for item in results:
          message_id = item
  </code></pre>