Return row after a Insert

Поиск
Список
Период
Сортировка
От Carel Combrink
Тема Return row after a Insert
Дата
Msg-id 20100329092119.fkomp24ocgw4ocgw@student.up.ac.za
обсуждение исходный текст
Ответы Re: Return row after a Insert  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
Список 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@tuks.co.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.



В списке pgsql-novice по дате отправления:

Предыдущее
От: dipti shah
Дата:
Сообщение: Designing Postgres Security Model
Следующее
От: "A. Kretschmer"
Дата:
Сообщение: Re: Return row after a Insert