Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 631d749

Browse files
committed
Remove the new UPSERT command tag and use INSERT instead.
Previously, INSERT with ON CONFLICT DO UPDATE specified used a new command tag -- UPSERT. It was introduced out of concern that INSERT as a command tag would be a misrepresentation for ON CONFLICT DO UPDATE, as some affected rows may actually have been updated. Alvaro Herrera noticed that the implementation of that new command tag was incomplete; in subsequent discussion we concluded that having it doesn't provide benefits that are in line with the compatibility breaks it requires. Catversion bump due to the removal of PlannedStmt->isUpsert. Author: Peter Geoghegan Discussion: [email protected]
1 parent 49ad32d commit 631d749

File tree

9 files changed

+15
-49
lines changed

9 files changed

+15
-49
lines changed

doc/src/sgml/protocol.sgml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3011,16 +3011,9 @@ CommandComplete (B)
30113011
<literal>INSERT <replaceable>oid</replaceable>
30123012
<replaceable>rows</replaceable></literal>, where
30133013
<replaceable>rows</replaceable> is the number of rows
3014-
inserted. However, if and only if <literal>ON CONFLICT
3015-
UPDATE</> is specified, then the tag is <literal>UPSERT
3016-
<replaceable>oid</replaceable>
3017-
<replaceable>rows</replaceable></literal>, where
3018-
<replaceable>rows</replaceable> is the number of rows inserted
3019-
<emphasis>or updated</emphasis>.
3020-
<replaceable>oid</replaceable> is the object ID of the
3021-
inserted row if <replaceable>rows</replaceable> is 1 and the
3022-
target table has OIDs, and (for the <literal>UPSERT</literal>
3023-
tag), the row was actually inserted rather than updated;
3014+
inserted. <replaceable>oid</replaceable> is the object ID
3015+
of the inserted row if <replaceable>rows</replaceable> is 1
3016+
and the target table has OIDs;
30243017
otherwise <replaceable>oid</replaceable> is 0.
30253018
</para>
30263019

doc/src/sgml/ref/insert.sgml

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -497,20 +497,13 @@ INSERT INTO <replaceable class="PARAMETER">table_name</replaceable> [ AS <replac
497497
<screen>
498498
INSERT <replaceable>oid</replaceable> <replaceable class="parameter">count</replaceable>
499499
</screen>
500-
However, in the event of an <literal>ON CONFLICT DO UPDATE</> clause
501-
(but <emphasis>not</emphasis> in the event of an <literal>ON
502-
CONFLICT DO NOTHING</> clause), the command tag reports the number of
503-
rows inserted or updated together, of the form
504-
<screen>
505-
UPSERT <replaceable>oid</replaceable> <replaceable class="parameter">count</replaceable>
506-
</screen>
507-
The <replaceable class="parameter">count</replaceable> is the number
508-
of rows inserted. If <replaceable class="parameter">count</replaceable>
509-
is exactly one, and the target table has OIDs, then
510-
<replaceable class="parameter">oid</replaceable> is the
511-
<acronym>OID</acronym>
512-
assigned to the inserted row (but not if there is only a single
513-
updated row). Otherwise <replaceable
500+
The <replaceable class="parameter">count</replaceable> is the
501+
number of rows inserted or updated. If <replaceable
502+
class="parameter">count</replaceable> is exactly one, and the
503+
target table has OIDs, then <replaceable
504+
class="parameter">oid</replaceable> is the <acronym>OID</acronym>
505+
assigned to the inserted row. The single row must have been
506+
inserted rather than updated. Otherwise <replaceable
514507
class="parameter">oid</replaceable> is zero.
515508
</para>
516509

src/backend/nodes/copyfuncs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ _copyPlannedStmt(const PlannedStmt *from)
8181
COPY_SCALAR_FIELD(queryId);
8282
COPY_SCALAR_FIELD(hasReturning);
8383
COPY_SCALAR_FIELD(hasModifyingCTE);
84-
COPY_SCALAR_FIELD(isUpsert);
8584
COPY_SCALAR_FIELD(canSetTag);
8685
COPY_SCALAR_FIELD(transientPlan);
8786
COPY_NODE_FIELD(planTree);

src/backend/nodes/outfuncs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ _outPlannedStmt(StringInfo str, const PlannedStmt *node)
243243
WRITE_UINT_FIELD(queryId);
244244
WRITE_BOOL_FIELD(hasReturning);
245245
WRITE_BOOL_FIELD(hasModifyingCTE);
246-
WRITE_BOOL_FIELD(isUpsert);
247246
WRITE_BOOL_FIELD(canSetTag);
248247
WRITE_BOOL_FIELD(transientPlan);
249248
WRITE_NODE_FIELD(planTree);

src/backend/optimizer/plan/planner.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,6 @@ standard_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
261261
result->queryId = parse->queryId;
262262
result->hasReturning = (parse->returningList != NIL);
263263
result->hasModifyingCTE = parse->hasModifyingCTE;
264-
result->isUpsert =
265-
(parse->onConflict && parse->onConflict->action == ONCONFLICT_UPDATE);
266264
result->canSetTag = parse->canSetTag;
267265
result->transientPlan = glob->transientPlan;
268266
result->planTree = top_plan;

src/backend/tcop/pquery.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,8 @@ ProcessQuery(PlannedStmt *plan,
202202
lastOid = queryDesc->estate->es_lastoid;
203203
else
204204
lastOid = InvalidOid;
205-
if (plan->isUpsert)
206-
snprintf(completionTag, COMPLETION_TAG_BUFSIZE,
207-
"UPSERT %u %u",
208-
lastOid, queryDesc->estate->es_processed);
209-
else
210-
snprintf(completionTag, COMPLETION_TAG_BUFSIZE,
211-
"INSERT %u %u",
212-
lastOid, queryDesc->estate->es_processed);
205+
snprintf(completionTag, COMPLETION_TAG_BUFSIZE,
206+
"INSERT %u %u", lastOid, queryDesc->estate->es_processed);
213207
break;
214208
case CMD_UPDATE:
215209
snprintf(completionTag, COMPLETION_TAG_BUFSIZE,
@@ -1362,10 +1356,7 @@ PortalRunMulti(Portal portal, bool isTopLevel,
13621356
* 0" here because technically there is no query of the matching tag type,
13631357
* and printing a non-zero count for a different query type seems wrong,
13641358
* e.g. an INSERT that does an UPDATE instead should not print "0 1" if
1365-
* one row was updated (unless the ON CONFLICT DO UPDATE, or "UPSERT"
1366-
* variant of INSERT was used to update the row, where it's logically a
1367-
* direct effect of the top level command). See QueryRewrite(), step 3,
1368-
* for details.
1359+
* one row was updated. See QueryRewrite(), step 3, for details.
13691360
*/
13701361
if (completionTag && completionTag[0] == '\0')
13711362
{
@@ -1375,8 +1366,6 @@ PortalRunMulti(Portal portal, bool isTopLevel,
13751366
sprintf(completionTag, "SELECT 0 0");
13761367
else if (strcmp(completionTag, "INSERT") == 0)
13771368
strcpy(completionTag, "INSERT 0 0");
1378-
else if (strcmp(completionTag, "UPSERT") == 0)
1379-
strcpy(completionTag, "UPSERT 0 0");
13801369
else if (strcmp(completionTag, "UPDATE") == 0)
13811370
strcpy(completionTag, "UPDATE 0");
13821371
else if (strcmp(completionTag, "DELETE") == 0)

src/bin/psql/common.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -894,12 +894,9 @@ PrintQueryResults(PGresult *results)
894894
success = StoreQueryTuple(results);
895895
else
896896
success = PrintQueryTuples(results);
897-
/*
898-
* if it's INSERT/UPSERT/UPDATE/DELETE RETURNING, also print status
899-
*/
897+
/* if it's INSERT/UPDATE/DELETE RETURNING, also print status */
900898
cmdstatus = PQcmdStatus(results);
901899
if (strncmp(cmdstatus, "INSERT", 6) == 0 ||
902-
strncmp(cmdstatus, "UPSERT", 6) == 0 ||
903900
strncmp(cmdstatus, "UPDATE", 6) == 0 ||
904901
strncmp(cmdstatus, "DELETE", 6) == 0)
905902
PrintQueryStatus(results);

src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 201505191
56+
#define CATALOG_VERSION_NO 201505231
5757

5858
#endif

src/include/nodes/plannodes.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ typedef struct PlannedStmt
4545

4646
bool hasModifyingCTE; /* has insert|update|delete in WITH? */
4747

48-
bool isUpsert; /* is it insert ... ON CONFLICT UPDATE? */
49-
5048
bool canSetTag; /* do I set the command result tag? */
5149

5250
bool transientPlan; /* redo plan when TransactionXmin changes? */

0 commit comments

Comments
 (0)