I'm working on the project where we are using :sql
schema format for the Active Record dumper (to support more complex logic like triggers).
We have a lot of views and I can see in the database/structure.sql
file that some of them have "predefined" schema with NULL
s like:
CREATE VIEW public.my_view AS
SELECT
NULL::integer AS record_id,
NULL::integer AS another_record_id,
NULL::double precision AS some_field;
Then, thousands of lines later, the definition is added with:
CREATE OR REPLACE VIEW public.my_view AS
-- actual query
I can't see any references to the view between schema "predefinition" and definition with my SQL query. Also, there are other views that are created right away (without that schema "predefinition").
I was looking in Active Record documentation but I couldn't find any hints. Rails uses pg_dump
under the hood but I don't see anything relevant in pg_dump
docs too.
Why some views require predefining the schema in advance, while others don't, even if none of them are referenced between predefinition and actual definition in database/structure.sql
file? Is it to prevent some race conditions when using yet another structure (like materialized views or something)?