In this example, we will look at how to create a PostgreSQL view with CREATE OR REPLACE VIEW statement.
Create a PostgreSQL View
You can create a Postgres view with
CREATE OR REPLACE VIEW statement. For example, to create a view for the existing
users table to find only users who are above a particular age. We can make use of
SELECT to get exactly the type of data and rows we want in the view to be able to dynamically query.
CREATE OR REPLACE VIEW "public"."old_users" ASSELECT users.id,users.ageFROM usersWHERE (users.age >= 60);
- Build apps and APIs 10x faster
- Built-in authorization and caching
- 8x more performant than hand-rolled APIs