pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruno Wolff III <bruno@wolff.to>
To: Jarek Pude?ko <jarek.pudelko@tech.ceti.pl>
Cc: pgsql-sql@postgresql.org
Subject: Re: return value of the trigger function
Date: Sat, 15 Jan 2005 03:00:22 -0600
Message-ID: <20050115090022.GA27243@wolff.to> (raw)
In-Reply-To: <41E28E05.2040307@tech.ceti.pl>
References: <41E28E05.2040307@tech.ceti.pl>

On Mon, Jan 10, 2005 at 15:15:33 +0100,
  Jarek Pude?ko <jarek.pudelko@tech.ceti.pl> wrote:
> Hi
> 
> I have big problem with a trigger function.
> Defs:
> 
> CREATE TABLE foo (id int2, name varchar(20));
> 
> foo.id cannot be serial or autoint because it will not be unique.
> 
> Now I need a trigger that return foo.id of the inserted record.
> 
> INSERT INTO foo VALUES (max(foo.id)+1,'junk');

If you are really doing the above, you probably do want to use serial.

If you insist on not doing this your app should do something like
lock table, select max(foo.id)+1 from id, and then nsert using the
value returned bye the select and then whatever else you want to do.

> 
> 
> IMHO the trigger should be:
> 
> CREATE TRIGGER tr_get_new_id
> AFTER INSERT on foo
> ON EACH ROW
> EXECUTE PROCEDURE get_new_id();
> 
> But I cannot create the function :(
> I don't know what type should be input and how about output? trigger or 
> int2?
> 
> TIA,
> 
> 
> -- 
> Jarek Pudelko
> JP272-RIPE
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)



view thread (2+ messages)

Message-ID: <20050115090022.GA27243@wolff.to>
Permalink:  ../20050115090022.GA27243@wolff.to/
Also on:    postgresql.org/message-id/20050115090022.GA27243@wolff.to

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: bruno@wolff.to, jarek.pudelko@tech.ceti.pl
  Subject: Re: return value of the trigger function
  In-Reply-To: <20050115090022.GA27243@wolff.to>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox