Skip to Content
PostgreSQL 10 Administration Cookbook - Fourth Edition
book

PostgreSQL 10 Administration Cookbook - Fourth Edition

by Simon Riggs, Gianni Ciolli
May 2018
Intermediate to advanced content levelIntermediate to advanced
576 pages
30h 25m
English
Packt Publishing
Content preview from PostgreSQL 10 Administration Cookbook - Fourth Edition

How it works…

In the rule-based example, we use the COALESCE function, which returns the first argument, if not null, or the second one otherwise. When the original INSERT statement does not specify a value in meters, then it uses the value in feet divided by 0.3048.

The second rule sets the value in meters to different expressions—if the value in meters was updated we use the new one; if the value in feet was updated, we use the new value in feet divided by 0.3048, and otherwise we use the old value in meters (that is, we don’t change it).

The logic implemented in the trigger function is similar to the one above: note that we use the TG_OP automatic variable to handle INSERT and UPDATE separately.

We've just scratched the surface of what ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PostgreSQL 13 Cookbook

PostgreSQL 13 Cookbook

Vallarapu Naga Avinash Kumar
PostgreSQL 9 Administration Cookbook - Second Edition

PostgreSQL 9 Administration Cookbook - Second Edition

Simon Riggs, GIANNI CIOLLI, Hannu Krosing, Gabriele Bartolini

Publisher Resources

ISBN: 9781788474924Supplemental Content