1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-29 10:41:53 +03:00

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.
This commit is contained in:
Tom Lane
2010-10-15 19:53:59 -04:00
parent 6ab42ae367
commit 07f1264dda
14 changed files with 333 additions and 44 deletions

View File

@ -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
*/