Thread: Update Rule

Update Rule

From
"Reinhard Hnat"
Date:
I have created a rule to update a view. This rule consists of three UPDATE
statments which update three different tables.

create rule update_abnahmezeilen as on update to abnahmezeilen do instead (
UPDATE seriennummern SET anmerkungen=new.anmerkungen,
abgenommen=new.abgenommen, lieferscheinnummer=new.lieferscheinnummer,
rechnungsnummer=new.rechnungsnummer,
abnahmenummer=new.abnahmenummer WHERE not new.sn is null and sn=new.sn;
UPDATE abs_komponenten SET bereits_geliefert=new.bereits_geliefert,
lieferscheinnummer=new.lieferscheinnummer,
rechnungsnummer=new.rechnungsnummer,
abnahmenummer=new.abnahmenummer,
abgenommen=new.abgenommen, anmerkungen=new.anmerkungen, menge=new.menge,
abnahmemenge=new.abnahmemenge,
gliederung=new.gliederung WHERE old.sn is null and linksn=new.linksn;
UPDATE reparaturschein SET gerät=new.gealogkomponente,
lieferscheinnummer=new.lieferscheinnummer,
rechnungsnummer=new.rechnungsnummer, seriennummer=new.sn,
gliederung=new.gliederung, anmerkungen = new.anmerkungen,
abnahmenummer=new.abnahmenummer,
abnahmemenge=new.abnahmemenge,abgenommen=new.abgenommen WHERE
linksn=old.linksn;);

This rule updates the tables ok but it returns 'UPDATE 0'. This causes the
calling Delphi program to produce an error. Is ther any possibility to
change this behaviour. It is not of interest how many records were changed
in fact it is only of interest if any records are changed or not.

Thanks in advance for any ideas
----
R.Hnat




Re: Update Rule

From
Tom Lane
Date:
"Reinhard Hnat" <hnat@logotronic.co.at> writes:
> This rule updates the tables ok but it returns 'UPDATE 0'. This causes the
> calling Delphi program to produce an error. Is ther any possibility to
> change this behaviour.

Only if you can re-order the updates.  See
http://www.postgresql.org/docs/8.0/static/rules-status.html

            regards, tom lane