Skip to Content
PostgreSQL: Up and Running, 3rd Edition
book

PostgreSQL: Up and Running, 3rd Edition

by Regina O. Obe, Leo S. Hsu
October 2017
Intermediate to advanced content levelIntermediate to advanced
314 pages
8h 13m
English
O'Reilly Media, Inc.
Book available
Content preview from PostgreSQL: Up and Running, 3rd Edition

Chapter 7. SQL: The PostgreSQL Way

PostgreSQL surpasses other database products in ANSI SQL compliance. It cements its lead by adding constructs that range from convenient syntax shorthands to avant-garde features that break the bounds of traditional SQL. In this chapter, we’ll cover some SQL tidbits not often found in other databases. For this chapter, you should have a working knowledge of SQL; otherwise, you may not appreciate the labor-saving amuse-bouche that PostgreSQL brings to the table.

Views

Well-designed relational databases store data in normalized form. To access this data across scattered tables, you write queries to join underlying tables. When you find yourself writing the same query over and over again, create a view. Simply put, a view is nothing more than a query permanently stored in the database.

Some purists have argued that one should always query a view, never tables. This means you must create a view for every table that you intend to query directly. The added layer of indirection eases management of permissions and facilitates abstraction of table data. We find this to be sound advice, but laziness gets the better of us.

Views in PostgreSQL have evolved over the years. Version 9.3 unveiled automatically updatable views. If your view draws from a single table and you include the primary key as an output column, you can issue an update command directly against your view. Data in the underlying table will follow suit.

Version 9.3 also introduced materialized views. ...

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

Learn PostgreSQL - Second Edition

Learn PostgreSQL - Second Edition

Luca Ferrari, Enrico Pirozzi
PostgreSQL 16 Administration Cookbook

PostgreSQL 16 Administration Cookbook

Gianni Ciolli, Boriss Mejías, Jimmy Angelakos, Vibhor Kumar, Simon Riggs

Publisher Resources

ISBN: 9781491963401Errata PageSupplemental Content