Return row after a Insert

From: Carel Combrink <s25291930(at)tuks(dot)co(dot)za>
To: pgsql-novice(at)postgresql(dot)org
Subject: Return row after a Insert
Date: 2010-03-29 07:21:19
Message-ID: 20100329092119.fkomp24ocgw4ocgw@student.up.ac.za
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I have a Table that looks something like this:

CREATE TABLE My_Table(
Entry integer PRIMARY KEY DEFAULT nextval('Number'),
TimeInsert timestamp DEFAULT current_timestamp,
Severity ENUM_Severity NOT NULL,
String varchar(512)
);

where Number is a SEQUENCE and ENUM_Severity is an ENUM

There are 2 things I want to do.

After an INSERT statement I want to be able to know what was the
'Entry' number I just added. I was thinking on creating an AFTER
trigger returning the new ROW or just the 'Entry'-number but the
documentation on triggers state that the return is ignored on a AFTER
trigger. How can I get this information. (I want to use this in a C
function, using SPI I assume).

I also want to use the ENUM 'ENUM_Severity' in my C functions (using
v1 calling). I want to create a function looking like this:
CREATE FUNCTION add_to_my_table(ENUM_Severity, text) RETURNS integer
AS 'myLibFile', 'add_to_my_table'
LANGUAGE C;
and then in the function insert the passed arguments into the table.
How do I handle the ENUM in my function (c function, dynamic library).
What function should I use to get the correct value (PG_GETARG_XXX(0);)?

Then this comes together. I want to call the function to insert the
new row and then return the new number if the user want to look at the
new entry after the function call.

Please help, and if it helps this is my 2nd week using postgreSQL (any
DB for that matter)

--
Carel Combrink
s25291930(at)tuks(dot)co(dot)za

This message and attachments are subject to a disclaimer. Please refer
to www.it.up.ac.za/documentation/governance/disclaimer/ for full
details. / Hierdie boodskap en aanhangsels is aan 'n vrywaringsklousule
onderhewig. Volledige besonderhede is by
www.it.up.ac.za/documentation/governance/disclaimer/ beskikbaar.

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message A. Kretschmer 2010-03-29 07:44:14 Re: Return row after a Insert
Previous Message L. Loewe 2010-03-29 00:19:04 slow plan on join when adding where clause