I have following migration:
execute <<-SQL
CREATE TABLE test_table(
name char(20)
);
INSERT INTO test_table(name) values ('test name');
CREATE MATERIALIZED VIEW test AS
SELECT * from test_table
WITH DATA;
SQL
Note that I add "WITH DATA".
This does not populate the data (as I get "materialized view has not been populated" error when I try to do concurrent refresh on the view) and adds "WITH NO DATA" in structure.sql
:
CREATE MATERIALIZED VIEW public.test AS
SELECT test_table.name
FROM public.test_table
WITH NO DATA;
What am I doing wrong? Postgres documentation about materialized views says The query is executed and used to populate the view at the time the command is issued (unless WITH NO DATA is used) So even without specifying "WITH DATA" it should generate "WITH DATA" by default but I get "WITH NO DATA" instead. When I use scenic library it does the same...
My issue seems to be similar to ActiveRecord migration not populating a Postgres materialized view
EDIT
I learnt that the data is actually populated on development environment (although it sets WITH NO DATA
in structure.sql
). The problem is in test environment, where it does not populate the data sometimes. Still investigating why... But structure.sql
is definitely not correct, unfortunately.