Re: Access last inserted tuple info...

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Luis D(dot) García <ldgarc(at)gmail(dot)com>
Cc: David Fetter <david(at)fetter(dot)org>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Access last inserted tuple info...
Date: 2007-01-25 16:02:03
Message-ID: 20070125160203.GD13744@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Jan 25, 2007 at 10:45:43AM -0400, Luis D. García wrote:
> Well, maybe I didn't make myself clear, this is what I need to do:
>
> I need to know the values of some fields (columns) from the last
> inserted tuple. The problem is that I need to do this in the moment
> I'm inserting a new one (all from the backend code) and compare
> the values between the new one (N.O) and the all ready inserted (A.R.I),
> and if the N.O fits some properties (according to the A.R.I) it must
> be decided if it has to be finally inserted or not.

Sounds like exactly what a trigger is for. The trigger can do what it
likes and depending on that, update the tuple or not.

However, you say you can't use triggers (which are just functions),
which begs the question: in what context is this? In what context is
this going to happen? "Last" relative to what?

> I think there's not to much difficulty on that, but until now I haven't
> found how to access that information. I can reach the HeapTuple
> structure according the A.R.I tuple, but I don't know how to access
> the information (values for its attributes) stored on it.

If you have a HeapTuple, there are functions to extract values out of
it and examine it. Is that what you're looking for?

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2007-01-25 16:03:13 Re: WAL Record Header Size Reduction
Previous Message Jim C. Nasby 2007-01-25 15:54:24 Re: how to plan for vacuum?