--查我们插入一条数据到数据库时,pg会返回给我们如下信息, postgres=# insert into test_2(id) select n from generate_series(1,10000) n; INSERT 0 10000 --第一列说明是插入动作,第三列表示插入了多少行,那么第二列是什么呐 --查看源码,可知 ProcessQuery(PlannedStmt *plan, const char *sourceText, ParamListInfo params, DestReceiver *dest, char *completionTag) { if (completionTag) { Oid lastOid; switch (queryDesc->operation) { case CMD_SELECT: snprintf(completionTag, COMPLETION_TAG_BUFSIZE, "SELECT %u", queryDesc->estate->es_processed); break; case CMD_INSERT: --如果执行的命令是 insert if (queryDesc->estate->es_processed == 1) --如果插入了一行 lastOid = queryDesc->estate->es_lastoid; --插入表的 OID else lastOid = InvalidOid; --插入的行数超过一行,则返回系统默认OID=0 snprintf(completionTag, COMPLETION_TAG_BUFSIZE, "INSERT %u %u", lastOid, queryDesc->estate->es_processed); --实际打印的输出 break; case CMD_UPDATE: snprintf(completionTag, COMPLETION_TAG_BUFSIZE, "UPDATE %u", queryDesc->estate->es_processed); break; case CMD_DELETE: snprintf(completionTag, COMPLETION_TAG_BUFSIZE, "DELETE %u", queryDesc->estate->es_processed); break; default: strcpy(completionTag, "???"); break; } } } --由以上可知 pg插入返回的第二列是一个oid --只有在表具有oid属性,且插入行数为一行时,第二列才实际被填充 postgres=# create table t1(id int) with (oids=true); CREATE TABLE postgres=# \d+ t1; Table "public.t1" Column | Type | Modifiers | Storage | Stats target | Description --------+---------+-----------+---------+--------------+------------- id | integer | | plain | | Has OIDs: yes --oid列被填充 postgres=# insert into t1 values(1); INSERT 33125 1 --超过一行,oid列被填充为0 postgres=# insert into t1 values(1),(2); INSERT 0 2