Skip to content

Commit 6392518

Browse files
committed
Add a HINT per suggestion from Michael Glaesemann. Also, tweak OLD/NEW
test to avoid expensive contain_vars_of_level() scan in the normal case where we're not inside a rule.
1 parent b737f85 commit 6392518

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/backend/parser/analyze.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.341 2006/08/02 01:59:46 joe Exp $
9+
* $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.342 2006/08/02 13:58:52 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -745,10 +745,12 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt,
745745
* construct to ensure that the values would be available while
746746
* evaluating the VALUES RTE. This is a shame. FIXME
747747
*/
748-
if (contain_vars_of_level((Node *) exprsLists, 0))
748+
if (pstate->p_rtable != NIL &&
749+
contain_vars_of_level((Node *) exprsLists, 0))
749750
ereport(ERROR,
750751
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
751-
errmsg("VALUES must not contain OLD or NEW references")));
752+
errmsg("VALUES must not contain OLD or NEW references"),
753+
errhint("Use SELECT ... UNION ALL ... instead.")));
752754

753755
/*
754756
* Generate the VALUES RTE
@@ -2264,10 +2266,12 @@ transformValuesClause(ParseState *pstate, SelectStmt *stmt)
22642266
* construct to ensure that the values would be available while
22652267
* evaluating the VALUES RTE. This is a shame. FIXME
22662268
*/
2267-
if (contain_vars_of_level((Node *) newExprsLists, 0))
2269+
if (list_length(pstate->p_rtable) != 1 &&
2270+
contain_vars_of_level((Node *) newExprsLists, 0))
22682271
ereport(ERROR,
22692272
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2270-
errmsg("VALUES must not contain OLD or NEW references")));
2273+
errmsg("VALUES must not contain OLD or NEW references"),
2274+
errhint("Use SELECT ... UNION ALL ... instead.")));
22712275

22722276
qry->rtable = pstate->p_rtable;
22732277
qry->jointree = makeFromExpr(pstate->p_joinlist, NULL);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy