agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Christian Kindler <christian.kindler@gmx.net>
To: Pavel Stehule <pavel.stehule@gmail.com>
Cc: Stephen Cook <sclists@gmail.com>
Cc: pgsql-sql@postgresql.org
Date: Thu, 29 Nov 2007 15:44:47 +0100
Message-ID: <20071129144447.292220@gmx.net> (raw)

Hmmm .... deamn ...

I have a realy big table (> 2'000'000 records). every second there are several inserts and updates. the thing is i need a last row reference depending on a foreing_key. 

something like this:

 id, foreign_key, last_id, value1, value1, date
>1<,           3,    null,     12,     13, 2007-01-01
>2<,           4,    null,     11,     10, 2007-01-01
  4,           3,     >1<,     12,     13, 2007-01-02
  5,           4,     >2<,     11,     10, 2007-01-02
...

of course the sequence can have holes so I have to calculate the real last row id. for now i calculate for each row by invoking a "select max(id) where foreign_key = $1" but this cost a lot of performance. I could do this easily with one update for the whole query - if i could know which foreign_key and which date range was performed.

any ideas?

thanks chris


On Thu, November 29, 2007 3:26 pm, Pavel Stehule wrote:
> On 29/11/2007, Stephen Cook <sclists@gmail.com> wrote:
>> I am curious (coming from a MS SQL Server background, I just started
>> playing with PostgreSQL recently).
> 
> yes, I belive. I was too. There are total different style of triggeres
> in Postgres. But If I can say, programming in Postgres is much more
> confortable. But It is different. You have to use ROW triggers.
> 
>>
>> What type of situation would warrant a statement-level trigger that
>> can't access the old and new values?  Without that access, isn't the
>> only information you get is the fact that an operation occurred on the
>> table?  Or am I missing something?
>>
>> -- Stephen
>>
> 
> Statement triggers can be used in some kind of auditing. Maybe. I
> didn't use it. And I use Postgres five years.
> 
> Pavel
>>
>>
>> Pavel Stehule wrote:
>> > Hello
>> >
>> > You cannot to access to values in statement trigger. Postgres doesn't
>> > support it.
>> >
>> > Regards
>> > Pavel Stehule
>> >
>> > On 29/11/2007, Christian Kindler <christian.kindler@gmx.net> wrote:
>> >> Hi
>> >>
>> >> Can anyone provide me a simple example of a statement-level trigger?
>> Problem is I do not know how to access the old.*, new.* values.
>> >>
>> >> Thanks
>> >> Chris
>> >> --
>> >> GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
>> >> Alle Infos und kostenlose Anmeldung:
>> http://www.gmx.net/de/go/freemail
>> >>
>> >> ---------------------------(end of
>> broadcast)---------------------------
>> >> TIP 1: if posting/reading through Usenet, please send an appropriate
>> >>        subscribe-nomail command to majordomo@postgresql.org so that
>> your
>> >>        message can get through to the mailing list cleanly
>> >>
>> >
>> > ---------------------------(end of
>> broadcast)---------------------------
>> > TIP 1: if posting/reading through Usenet, please send an appropriate
>> >        subscribe-nomail command to majordomo@postgresql.org so that
>> your
>> >        message can get through to the mailing list cleanly
>> >
>>
>> ---------------------------(end of broadcast)---------------------------
>> TIP 7: You can help support the PostgreSQL project by donating at
>>
>>                 http://www.postgresql.org/about/donate
>>
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
> 
>                http://www.postgresql.org/docs/faq
>
-- 
cu
Chris

Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger



Message-ID: <20071129144447.292220@gmx.net>
Permalink:  ../20071129144447.292220@gmx.net/
Also on:    postgresql.org/message-id/20071129144447.292220@gmx.net

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: christian.kindler@gmx.net, pavel.stehule@gmail.com, sclists@gmail.com
  Subject: Re: 
  In-Reply-To: <20071129144447.292220@gmx.net>

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

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