Skip to content

Commit a89112b

Browse files
committed
feat: add command_tag_omit_oid GUC to drop legacy OID from INSERT tag
Add a new boolean GUC command_tag_omit_oid (default off) that controls whether the legacy OID field is included in INSERT command completion tags. When enabled, INSERT returns 'INSERT N' instead of 'INSERT 0 N'. The '0' is a vestige from PostgreSQL 11 and earlier when tables could have OIDs. The OID field has been hardcoded to 0 (InvalidOid) since PostgreSQL 12, but remains in the wire protocol for backward compatibility. This GUC is per-session (PGC_USERSET) and supports SET LOCAL for per-transaction control. Also update libpq's PQcmdTuples() to handle both formats gracefully, so client applications work correctly regardless of the server setting. Files changed: - src/backend/tcop/cmdtag.c: GUC variable + conditional OID emission - src/backend/utils/misc/guc_parameters.dat: GUC registration - src/include/tcop/cmdtag.h: extern declaration - src/interfaces/libpq/fe-exec.c: handle INSERT with/without OID field
1 parent b6eb8dd commit a89112b

4 files changed

Lines changed: 29 additions & 7 deletions

File tree

src/backend/tcop/cmdtag.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "postgres.h"
1515

1616
#include "tcop/cmdtag.h"
17+
#include "utils/guc.h"
1718
#include "utils/builtins.h"
1819

1920

@@ -36,6 +37,9 @@ static const CommandTagBehavior tag_behavior[] = {
3637

3738
#undef PG_CMDTAG
3839

40+
/* GUC variable: omit legacy OID field from INSERT command tag */
41+
bool command_tag_omit_oid = false;
42+
3943
void
4044
InitializeQueryCompletion(QueryCompletion *qc)
4145
{
@@ -145,7 +149,7 @@ BuildQueryCompletionString(char *buff, const QueryCompletion *qc,
145149
*/
146150
if (command_tag_display_rowcount(tag) && !nameonly)
147151
{
148-
if (tag == CMDTAG_INSERT)
152+
if (tag == CMDTAG_INSERT && !command_tag_omit_oid)
149153
{
150154
*bufp++ = ' ';
151155
*bufp++ = '0';

src/backend/utils/misc/guc_parameters.dat

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@
426426
options => 'client_message_level_options',
427427
},
428428

429+
429430
{ name => 'cluster_name', type => 'string', context => 'PGC_POSTMASTER', group => 'PROCESS_TITLE',
430431
short_desc => 'Sets the name of the cluster, which is included in the process title.',
431432
flags => 'GUC_IS_NAME',
@@ -435,6 +436,14 @@
435436
},
436437

437438
# we have no microseconds designation, so can't supply units here
439+
440+
{ name => 'command_tag_omit_oid', type => 'bool', context => 'PGC_USERSET', group => 'CLIENT_CONN_STATEMENT',
441+
short_desc => 'Omits the legacy OID field from INSERT command completion tags.',
442+
long_desc => 'When enabled, INSERT returns "INSERT N" instead of "INSERT 0 N". The "0" is a legacy placeholder from when tables could have OIDs (removed in PostgreSQL 12).',
443+
variable => 'command_tag_omit_oid',
444+
boot_val => 'false',
445+
includes => 'tcop/cmdtag.h',
446+
},
438447
{ name => 'commit_delay', type => 'int', context => 'PGC_SUSET', group => 'WAL_SETTINGS',
439448
short_desc => 'Sets the delay in microseconds between transaction commit and flushing WAL to disk.',
440449
variable => 'CommitDelay',

src/include/tcop/cmdtag.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ extern bool command_tag_display_rowcount(CommandTag commandTag);
5656
extern bool command_tag_event_trigger_ok(CommandTag commandTag);
5757
extern bool command_tag_table_rewrite_ok(CommandTag commandTag);
5858
extern CommandTag GetCommandTagEnum(const char *commandname);
59+
60+
/* GUC variable: controls legacy OID in INSERT command tag */
61+
extern bool command_tag_omit_oid;
5962
extern Size BuildQueryCompletionString(char *buff, const QueryCompletion *qc,
6063
bool nameonly);
6164

src/interfaces/libpq/fe-exec.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3847,12 +3847,18 @@ PQcmdTuples(PGresult *res)
38473847
if (strncmp(res->cmdStatus, "INSERT ", 7) == 0)
38483848
{
38493849
p = res->cmdStatus + 7;
3850-
/* INSERT: skip oid and space */
3851-
while (*p && *p != ' ')
3852-
p++;
3853-
if (*p == 0)
3854-
goto interpret_error; /* no space? */
3855-
p++;
3850+
/* INSERT: handle both "INSERT oid count" and "INSERT count" */
3851+
{
3852+
char *q = p;
3853+
while (*q && *q != ' ')
3854+
q++;
3855+
if (*q == ' ')
3856+
{
3857+
/* Old format: "INSERT oid count" - skip oid and space */
3858+
p = q + 1;
3859+
}
3860+
/* else: new format "INSERT count" - p already points to count */
3861+
}
38563862
}
38573863
else if (strncmp(res->cmdStatus, "SELECT ", 7) == 0 ||
38583864
strncmp(res->cmdStatus, "DELETE ", 7) == 0 ||

0 commit comments

Comments
 (0)