pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedQuestion on rule
2+ messages / 2 participants
[nested] [flat]
* Question on rule
@ 2009-02-21 08:43 Michael Monnerie <michael.monnerie@is.it-management.at>
0 siblings, 1 reply; 2+ messages in thread
From: Michael Monnerie @ 2009-02-21 08:43 UTC (permalink / raw)
To: pgsql-admin
I have a question to creating a rule:
CREATE RULE dbmail_mailboxes_autocreate AS ON INSERT TO dbmail_users DO
ALSO insert into dbmail_mailboxes (owner_idnr,name) values
(NEW.user_idnr,'INBOX'), (NEW.user_idnr,'Gesendete Objekte'),
(NEW.user_idnr,'Entwürfe'), (NEW.user_idnr,'Junk'),
(NEW.user_idnr,'Papierkorb');
ERROR: VALUES must not contain OLD or NEW references
TIP: Use SELECT ... UNION ALL ... instead.
But in http://www.postgresql.org/docs/8.3/interactive/rules-update.html
the examples also use NEW in the values. Or can I only use a rule within
the same table?
If I need to use a TRIGGER: I tried with creating a function, but I
don't know how to pass the current user_idnr to that function from the
trigger. I managed to create the function:
CREATE FUNCTION dbmail_mailboxes_autocreate_function(user_idnr bigint)
returns integer AS $$ BEGIN insert into dbmail_mailboxes
(owner_idnr,name) values (user_idnr,'INBOX'), (user_idnr,'Gesendete
Objekte'), (user_idnr,'Entwürfe'), (user_idnr,'Junk'),
(user_idnr,'Papierkorb'); END; $$ LANGUAGE plpgSQL;
But I don't know how to do the trigger. Can someone help me?
mfg zmi
--
// Michael Monnerie, Ing.BSc ----- http://it-management.at
// Tel: 0660 / 415 65 31 .network.your.ideas.
// PGP Key: "curl -s http://zmi.at/zmi.asc | gpg --import"
// Fingerprint: AC19 F9D5 36ED CD8A EF38 500E CE14 91F7 1C12 09B4
// Keyserver: wwwkeys.eu.pgp.net Key-ID: 1C1209B4
Attachments:
signature.asc (application/pgp-signature, 196B) download
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Question on rule
@ 2009-02-23 13:58 Achilleas Mantzios <achill@matrix.gatewaynet.com>
parent: Michael Monnerie <michael.monnerie@is.it-management.at>
0 siblings, 0 replies; 2+ messages in thread
From: Achilleas Mantzios @ 2009-02-23 13:58 UTC (permalink / raw)
To: pgsql-admin; +Cc: Michael Monnerie <michael.monnerie@is.it-management.at>
Óôéò Saturday 21 February 2009 10:43:35 ï/ç Michael Monnerie Ýãñáøå:
> $$ LANGUAGE plpgSQL;
do smth like:
CREATE or REPLACE function foofunc() RETURNS TRIGGER as $$
BEGIN
insert into test2(descr) values(new.descr);
INSERT into test2(descr) values(new.descr||'FOOBAR');
RETURN NEW;
END
$$ LANGUAGE plpgSQL;
CREATE TRIGGER foofunc_trig AFTER INSERT ON test1 FOR EACH ROW EXECUTE PROCEDURE foofunc();
--
Achilleas Mantzios
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2009-02-23 13:58 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-02-21 08:43 Question on rule Michael Monnerie <michael.monnerie@is.it-management.at>
2009-02-23 13:58 ` Achilleas Mantzios <achill@matrix.gatewaynet.com>
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