How to cast a general record?

Поиск
Список
Период
Сортировка
От Gerhard Heift
Тема How to cast a general record?
Дата
Msg-id 20090101134108.GA19601@kawo1.rwth-aachen.de
обсуждение исходный текст
Ответы Re: How to cast a general record?  (Martin Gainty <mgainty@hotmail.com>)
Re: How to cast a general record?  ("Albe Laurenz" <laurenz.albe@wien.gv.at>)
Solution for tranaction independent logging in same database?  (Gerhard Heift <ml-postgresql-20081012-3518@gheift.de>)
Список pgsql-general
Hello,

I want to log with triggers or in functions, and these logs should be
independet of the transaction. Beside i want to have the information
which action was commited and which not.

So my idea was to log into the same database with dblink, return the
primary keys and add them into a commit table.

But my problem is, that I do not now how to write the rule properly.

My schema locks like this:

CREATE TABLE log_msg (
  msg_id bigserial not null,
  msg text not null,
  constraint msg_pkey primary key (msg_id)
);

CREATE TABLE log_commit (
  msg_id bigint not null,
  constraint msg_pkey primary key (msg_id)
);

CREATE VIEW log AS
SELECT log_msg.*, log_commit.msg_id IS NOT NULL AS commited
FROM log_msg LEFT JOIN log_commit USING (msg_id);

CREATE OR REPLACE RULE "insert_log" AS
  ON INSERT TO log DO INSTEAD

 -- now this is pseudo code:
INSERT INTO log_commit (msg_id)
SELECT dblink('dbname=samedb', 'INSERT log_msg (msg) VALUES ('
  || quote_literal(new.msg)
  || ') RETURNING msg_id');

Regards,
  Gerhard

Вложения

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

Предыдущее
От: Craig Ringer
Дата:
Сообщение: Re: postgres block_size problem
Следующее
От: Martin Gainty
Дата:
Сообщение: Re: How to cast a general record?