Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0f249fe

Browse files
committed
Fix busted Assert for CREATE MATVIEW ... WITH NO DATA.
Commit874fe3a changed the command tag returned for CREATE MATVIEW/CREATETABLE AS ... WITH NO DATA, but missed that there was code in spi.c thatexpected the command tag to always be "SELECT". Fortunately, theconsequence was only an Assert failure, so this oversight should have noimpact in production builds.Since this code path was evidently un-exercised, add a regression test.Per report from Shivam Saxena. Back-patch to 9.3, like the previous commit.Michael PaquierReport: <97218716-480B-4527-B5CD-D08D798A0C7B@dresources.com>
1 parentfd5a2db commit0f249fe

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

‎src/backend/executor/spi.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,8 +2226,12 @@ _SPI_execute_plan(SPIPlanPtr plan, ParamListInfo paramLI,
22262226
pg_strtouint64(completionTag+7,NULL,10);
22272227
else
22282228
{
2229-
/* Must be an IF NOT EXISTS that did nothing */
2230-
Assert(ctastmt->if_not_exists);
2229+
/*
2230+
* Must be an IF NOT EXISTS that did nothing, or a
2231+
* CREATE ... WITH NO DATA.
2232+
*/
2233+
Assert(ctastmt->if_not_exists||
2234+
ctastmt->into->skipData);
22312235
_SPI_current->processed=0;
22322236
}
22332237

‎src/test/regress/expected/matview.out

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,3 +557,28 @@ REFRESH MATERIALIZED VIEW mvtest_mv_foo;
557557
REFRESH MATERIALIZED VIEW CONCURRENTLY mvtest_mv_foo;
558558
DROP OWNED BY regress_user_mvtest CASCADE;
559559
DROP ROLE regress_user_mvtest;
560+
-- make sure that create WITH NO DATA works via SPI
561+
BEGIN;
562+
CREATE FUNCTION mvtest_func()
563+
RETURNS void AS $$
564+
BEGIN
565+
CREATE MATERIALIZED VIEW mvtest1 AS SELECT 1 AS x;
566+
CREATE MATERIALIZED VIEW mvtest2 AS SELECT 1 AS x WITH NO DATA;
567+
END;
568+
$$ LANGUAGE plpgsql;
569+
SELECT mvtest_func();
570+
mvtest_func
571+
-------------
572+
573+
(1 row)
574+
575+
SELECT * FROM mvtest1;
576+
x
577+
---
578+
1
579+
(1 row)
580+
581+
SELECT * FROM mvtest2;
582+
ERROR: materialized view "mvtest2" has not been populated
583+
HINT: Use the REFRESH MATERIALIZED VIEW command.
584+
ROLLBACK;

‎src/test/regress/sql/matview.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,17 @@ REFRESH MATERIALIZED VIEW mvtest_mv_foo;
226226
REFRESH MATERIALIZED VIEW CONCURRENTLY mvtest_mv_foo;
227227
DROP OWNED BY regress_user_mvtest CASCADE;
228228
DROP ROLE regress_user_mvtest;
229+
230+
-- make sure that create WITH NO DATA works via SPI
231+
BEGIN;
232+
CREATEFUNCTIONmvtest_func()
233+
RETURNS voidAS $$
234+
BEGIN
235+
CREATE MATERIALIZED VIEW mvtest1ASSELECT1AS x;
236+
CREATE MATERIALIZED VIEW mvtest2ASSELECT1AS x WITH NO DATA;
237+
END;
238+
$$ LANGUAGE plpgsql;
239+
SELECT mvtest_func();
240+
SELECT*FROM mvtest1;
241+
SELECT*FROM mvtest2;
242+
ROLLBACK;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp