title: How to return auto generated id in insert query in postgres sql
body: <p>I have a table.this is the script for my table:-</p>
  
  <pre><code>CREATE TABLE news
  (
    news_id bigint NOT NULL DEFAULT nextval('news_seq'::regclass),
    title character varying(1024),
    description character varying(2024),
    CONSTRAINT pk_news_newsid PRIMARY KEY (news_id)  
  )
  WITH (
    OIDS=FALSE
  );
  ALTER TABLE news OWNER TO viewer;
  </code></pre>
  
  <p>Now I want to get the auto generated  <code>news_id</code> on insert the new record in the table.</p>
  
  <p><strong>This is C# function for insert the news:-</strong></p>
  
  <pre><code> public Int64 AddNews(News newNews)
      {
          string query = string.Empty;
          try
          {
              string dateFormat = ConfigurationManager.AppSettings["DateFormat"];
              NpgsqlParameter[] parm = new NpgsqlParameter[2];
              parm[0] = new NpgsqlParameter("title", newNews.NewsTitle);
              parm[1] = new NpgsqlParameter("des", newNews.NewsDescription);
  
              query = @" INSERT INTO   news(title, description)
                              VALUES   (:title, :des) 
                           Returning   news_id";
  
              int id=NpgSqlHelper.ExecuteNonQuery(connectionString, CommandType.Text, query, parm);
  
              return id;
          }
          catch (Exception ex)
          {
              throw new Exception(ex.Message);
          }
      }
  </code></pre>
  
  <p><code>On executing this function I always get the -1 value</code></p>
  
  <p>Thanks in advance</p>
  
  <p>While executing the following query on pgAdmin gives correct result:</p>
  
  <pre><code>INSERT INTO news(title, description)
      VALUES ('title','description')
      Returning news_id
  </code></pre>