pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
update table with suppress_redundant_updates_trigger()
3+ messages / 2 participants
[nested] [flat]

* update table with suppress_redundant_updates_trigger()
@ 2019-02-25 18:42  wambacher@posteo.de
  0 siblings, 2 replies; 3+ messages in thread

From: wambacher@posteo.de @ 2019-02-25 18:42 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Hi,

i'm doing a lot of updates in my database, but most of them are not
necessary at all (sorry, just detected it)

Therefore i installed a trigger to minimize real updates.

create trigger suppress_redundant_updates_boundaries
   before update on boundaries
   for each row execute procedure suppress_redundant_updates_trigger();

Is there a way to get the count of the real table updates?

Using pl/pgsql i'm updating boundaries  with

                  update boundaries
                     set id             = bT2.id,
                         country        = bT2.country,
                         type           = 'admin',   
                         value          = bT2.value,
...
                        ,qm             = bT2.qm
                        ,lwqm           =
st_area(geography(coalesce(xlandarea,rT.way)))
                   where id = bT2.id;

                   if (found) then
                      if (debug > 0) then raise notice 'real db update
of % done 2', bT2.id; end if;
                      updatedDB := updatedDB + 1;
                   end if;

i get a "wrong" result, because "found" is always true, even when the
records are identical (hope so) and an update should be suppressed by
the trigger.

Question: will "found" be set when update has been blocked by the
trigger - or does that not matter?

if "found" is always true: what else can i do?

regards

walter

-- 
My projects:

Admin Boundaries of the World <https://wambachers-osm.website/boundaries;
Missing Boundaries
<https://wambachers-osm.website/index.php/projekte/internationale-administrative-grenzen/missing-boun...;
Emergency Map <https://wambachers-osm.website/emergency;
Postal Code Map (Germany only) <https://wambachers-osm.website/plz;
Fools (QA for zipcodes in Germany) <https://wambachers-osm.website/fools;
Postcode Boundaries of Germany <https://wambachers-osm.website/pcoundaries;


^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: update table with suppress_redundant_updates_trigger()
@ 2019-02-25 21:41  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: wambacher@posteo.de
  1 sibling, 0 replies; 3+ messages in thread

From: Adrian Klaver @ 2019-02-25 21:41 UTC (permalink / raw)
  To: wambacher@posteo.de; pgsql-general@lists.postgresql.org

On 2/25/19 10:42 AM, wambacher@posteo.de wrote:
> Hi,
> 
> i'm doing a lot of updates in my database, but most of them are not 
> necessary at all (sorry, just detected it)

Would it not be easier to just not do the unnecessary updates?

Or to put it another way what distinguishes necessary/unnecessary?

> 
> Therefore i installed a trigger to minimize real updates.
> 
> create trigger suppress_redundant_updates_boundaries
>     before update on boundaries
>     for each row execute procedure suppress_redundant_updates_trigger();
> 
> Is there a way to get the count of the real table updates?
> 
> Using pl/pgsql i'm updating boundaries  with
> 
>                    update boundaries
>                       set id             = bT2.id,
>                           country        = bT2.country,
>                           type           = 'admin',
>                           value          = bT2.value,
> ...
>                          ,qm             = bT2.qm
>                          ,lwqm           = 
> st_area(geography(coalesce(xlandarea,rT.way)))
>                     where id = bT2.id;
> 
>                     if (found) then
>                        if (debug > 0) then raise notice 'real db update 
> of % done 2', bT2.id; end if;
>                        updatedDB := updatedDB + 1;
>                     end if;
> 
> i get a "wrong" result, because "found" is always true, even when the 
> records are identical (hope so) and an update should be suppressed by 
> the trigger. >
> Question: will "found" be set when update has been blocked by the 
> trigger - or does that not matter?
> 
> if "found" is always true: what else can i do?

Untested:

IF NEW.* != OLD.* THEN
	RETURN NEW.*
ELSE
	RETURN NULL
END IF;
> 
> regards
> 
> walter
> 
> -- 
> My projects:
> 
> Admin Boundaries of the World <https://wambachers-osm.website/boundaries;
> Missing Boundaries 
> <https://wambachers-osm.website/index.php/projekte/internationale-administrative-grenzen/missing-boun...;
> Emergency Map <https://wambachers-osm.website/emergency;
> Postal Code Map (Germany only) <https://wambachers-osm.website/plz;
> Fools (QA for zipcodes in Germany) <https://wambachers-osm.website/fools;
> Postcode Boundaries of Germany <https://wambachers-osm.website/pcoundaries;


-- 
Adrian Klaver
adrian.klaver@aklaver.com




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: update table with suppress_redundant_updates_trigger()
@ 2019-02-26 09:10  wambacher@posteo.de
  parent: wambacher@posteo.de
  1 sibling, 0 replies; 3+ messages in thread

From: wambacher@posteo.de @ 2019-02-26 09:10 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Problem "solved".

"found" will be true of false depending on the trigger action.

update done -> found = true, update not done -> found=false.

But: The trigger sometimes allows updates where no data has been
changed! That is another problem to be solved :(

Regards

walter

Am 25.02.19 um 19:42 schrieb wambacher@posteo.de:
>
> Hi,
>
> i'm doing a lot of updates in my database, but most of them are not
> necessary at all (sorry, just detected it)
>
> Therefore i installed a trigger to minimize real updates.
>
> create trigger suppress_redundant_updates_boundaries
>    before update on boundaries
>    for each row execute procedure suppress_redundant_updates_trigger();
>
> Is there a way to get the count of the real table updates?
>
> Using pl/pgsql i'm updating boundaries  with
>
>                   update boundaries
>                      set id             = bT2.id,
>                          country        = bT2.country,
>                          type           = 'admin',   
>                          value          = bT2.value,
> ...
>                         ,qm             = bT2.qm
>                         ,lwqm           =
> st_area(geography(coalesce(xlandarea,rT.way)))
>                    where id = bT2.id;
>
>                    if (found) then
>                       if (debug > 0) then raise notice 'real db update
> of % done 2', bT2.id; end if;
>                       updatedDB := updatedDB + 1;
>                    end if;
>
> i get a "wrong" result, because "found" is always true, even when the
> records are identical (hope so) and an update should be suppressed by
> the trigger.
>
> Question: will "found" be set when update has been blocked by the
> trigger - or does that not matter?
>
> if "found" is always true: what else can i do?
>
> regards
>
> walter
>
> -- 
> My projects:
>
> Admin Boundaries of the World <https://wambachers-osm.website/boundaries;
> Missing Boundaries
> <https://wambachers-osm.website/index.php/projekte/internationale-administrative-grenzen/missing-boun...;
> Emergency Map <https://wambachers-osm.website/emergency;
> Postal Code Map (Germany only) <https://wambachers-osm.website/plz;
> Fools (QA for zipcodes in Germany) <https://wambachers-osm.website/fools;
> Postcode Boundaries of Germany
> <https://wambachers-osm.website/pcoundaries;
-- 
My projects:

Admin Boundaries of the World <https://wambachers-osm.website/boundaries;
Missing Boundaries
<https://wambachers-osm.website/index.php/projekte/internationale-administrative-grenzen/missing-boun...;
Emergency Map <https://wambachers-osm.website/emergency;
Postal Code Map (Germany only) <https://wambachers-osm.website/plz;
Fools (QA for zipcodes in Germany) <https://wambachers-osm.website/fools;
Postcode Boundaries of Germany <https://wambachers-osm.website/pcoundaries;


^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2019-02-26 09:10 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-02-25 18:42 update table with suppress_redundant_updates_trigger() wambacher@posteo.de
2019-02-25 21:41 ` Adrian Klaver <adrian.klaver@aklaver.com>
2019-02-26 09:10 ` wambacher@posteo.de

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