sequence values question - Mailing list pgsql-general

From mmiranda@americatel.com.sv
Subject sequence values question
Date
Msg-id 76E0DAA32C39D711B6EC0002B364A6FA044EBD95@amsal01exc01.americatel.com.sv
Whole thread Raw
Responses Re: sequence values question  (Franco Bruno Borghesi <fborghesi@gmail.com>)
List pgsql-general
Hi, how can i know the values generated by a column of type serial?
I mean, i have the following table

productos
(
  id serial,
  desc varchar(50)
)

select * from productos;

+-----+------------+
| id  | desc       |
+-----+------------+
|   1 | ecard1     |
|   2 | ecard2     |
|   3 | ecard3     |
|   4 | ecard4     |
|   5 | ecard5     |
+-----+------------+

I insert a row using a SP, i want to return the id and desc of the new
product in the table.
this is an example of the hypothetical SP

CREATE OR REPLACE FUNCTION insert_row(text) returns text language plpgsql
AS $$
DECLARE
  vdesc alias for $1;
BEGIN
    INSERT INTO productos (desc) VALUES (vdesc);
    RETURN (new id ???) || ',' || vdesc;
END;
$$
LANGUAGE 'plpgsql' VOLATILE;


I know i can get the last value using currval(text), and add 1 to the next
values, is this the only way?, what if i want to insert several products?,
should i  return a record ?
thanks


pgsql-general by date:

Previous
From: Just Someone
Date:
Subject: Hosting options on Postgres - what's best?
Next
From: Tom Lane
Date:
Subject: Re: [PERFORM] "Hash index" vs. "b-tree index" (PostgreSQL