Views[src]
Views wrap a SQL query. Use {TableName} to reference tables and {TableName.column} to reference columns. Immigrant substitutes actual database names:
view ActiveUsers = sql"""
SELECT * FROM {User}
WHERE {User.active} = true
""";
Materialized views use view.materialized:
view.materialized UserStats = sql"""
SELECT {User.user_id}, count(*) as post_count
FROM {User}
JOIN {Post} ON {Post.user_id} = {User.user_id}
GROUP BY {User.user_id}
""";
When referenced tables or columns are renamed, immigrant automatically recreates the view with updated names.
Views may carry an attribute block before =, holding role grants and the @security_definer opt-out:
view ActiveUsers {
@role Reader {
select;
};
} = sql"SELECT * FROM {User}";
Views are security invoker by default, see the Roles, Grants and RLS page.
Last updated 2026-09-13 #c15a622