aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/ruleutils.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2010-10-15 19:53:59 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2010-10-15 19:55:25 -0400
commit07f1264dda0e776a7e329b091c127059bce8cc54 (patch)
treec77493be3b7c010de069a431035b80db720b0969 /src/backend/utils/adt/ruleutils.c
parent6ab42ae36713b1e6f961c37e22f99d3e6267523b (diff)
downloadpostgresql-07f1264dda0e776a7e329b091c127059bce8cc54.tar.gz
postgresql-07f1264dda0e776a7e329b091c127059bce8cc54.zip
Allow WITH clauses to be attached to INSERT, UPDATE, DELETE statements.
This is not the hoped-for facility of using INSERT/UPDATE/DELETE inside a WITH, but rather the other way around. It seems useful in its own right anyway. Note: catversion bumped because, although the contents of stored rules might look compatible, there's actually a subtle semantic change. A single Query containing a WITH and INSERT...VALUES now represents writing the WITH before the INSERT, not before the VALUES. While it's not clear that that matters to anyone, it seems like a good idea to have it cited in the git history for catversion.h. Original patch by Marko Tiikkaja, with updating and cleanup by Hitoshi Harada.
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r--src/backend/utils/adt/ruleutils.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index b5437612a92..22ba948e732 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -3352,6 +3352,9 @@ get_insert_query_def(Query *query, deparse_context *context)
ListCell *l;
List *strippedexprs;
+ /* Insert the WITH clause if given */
+ get_with_clause(query, context);
+
/*
* If it's an INSERT ... SELECT or VALUES (...), (...), ... there will be
* a single RTE for the SELECT or VALUES.
@@ -3451,15 +3454,11 @@ get_insert_query_def(Query *query, deparse_context *context)
}
else if (values_rte)
{
- /* A WITH clause is possible here */
- get_with_clause(query, context);
/* Add the multi-VALUES expression lists */
get_values_def(values_rte->values_lists, context);
}
else
{
- /* A WITH clause is possible here */
- get_with_clause(query, context);
/* Add the single-VALUES expression list */
appendContextKeyword(context, "VALUES (",
-PRETTYINDENT_STD, PRETTYINDENT_STD, 2);
@@ -3489,6 +3488,9 @@ get_update_query_def(Query *query, deparse_context *context)
RangeTblEntry *rte;
ListCell *l;
+ /* Insert the WITH clause if given */
+ get_with_clause(query, context);
+
/*
* Start the query with UPDATE relname SET
*/
@@ -3570,6 +3572,9 @@ get_delete_query_def(Query *query, deparse_context *context)
StringInfo buf = context->buf;
RangeTblEntry *rte;
+ /* Insert the WITH clause if given */
+ get_with_clause(query, context);
+
/*
* Start the query with DELETE FROM relname
*/