Method: Sequel::Database#create_view
- Defined in:
- lib/sequel/database/schema_methods.rb
#create_view(name, source, options = OPTS) ⇒ Object
Creates a view based on a dataset or an SQL string:
DB.create_view(:cheap_items, "SELECT * FROM items WHERE price < 100")
# CREATE VIEW cheap_items AS
# SELECT * FROM items WHERE price < 100
DB.create_view(:ruby_items, DB[:items].where(:category => 'ruby'))
# CREATE VIEW ruby_items AS
# SELECT * FROM items WHERE (category = 'ruby')
DB.create_view(:checked_items, DB[:items].where(:foo), :check=>true)
# CREATE VIEW checked_items AS
# SELECT * FROM items WHERE foo
# WITH CHECK OPTION
Options:
- :columns
-
The column names to use for the view. If not given, automatically determined based on the input dataset.
- :check
-
Adds a WITH CHECK OPTION clause, so that attempting to modify rows in the underlying table that would not be returned by the view is not allowed. This can be set to :local to use WITH LOCAL CHECK OPTION.
PostgreSQL/SQLite specific option:
- :temp
-
Create a temporary view, automatically dropped on disconnect.
PostgreSQL specific options:
- :materialized
-
Creates a materialized view, similar to a regular view, but backed by a physical table.
- :recursive
-
Creates a recursive view. As columns must be specified for recursive views, you can also set them as the value of this option. Since a recursive view requires a union that isn’t in a subquery, if you are providing a Dataset as the source argument, if should probably call the union method with the :all=>true and :from_self=>false options.
287 288 289 290 291 |
# File 'lib/sequel/database/schema_methods.rb', line 287 def create_view(name, source, = OPTS) execute_ddl(create_view_sql(name, source, )) remove_cached_schema(name) nil end |