Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-novice by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group