PostgreSQL INSERT 确认参数是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3835314/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What Do PostgreSQL INSERT confirmation params mean?
提问by katir
In my LiveCode Server app I'm getting a dberr returned on insertion but no explicit error code.
在我的 LiveCode Server 应用程序中,我在插入时返回了 dberr,但没有明确的错误代码。
I went on a terminal and did the insertion by hand as user Postgres.
我在终端上以用户 Postgres 的身份手动插入。
%My_Dbase=# INSERT INTO new-table (first_name, last_name, anonymous) VALUES ('batman', 'Moonboy', TRUE);
The psql process returns:
psql 进程返回:
INSERT 0 1
What does this line mean? Besides the primary table I also have a sequence to increment the primary key ID (int) of the main table.
这条线是什么意思?除了主表,我还有一个序列来增加主表的主键 ID (int)。
If I check the data, the data is inserted, the primary key is increment by one and everything seems fine, I'm not sure why my app is returning an error (could be a bug in the app or my code).
如果我检查数据,插入数据,主键加一,一切看起来都很好,我不知道为什么我的应用程序返回错误(可能是应用程序或我的代码中的错误)。
But if I knew what INSERT 0 1
meant, that would help me assure myself that:
但如果我知道这INSERT 0 1
意味着什么,那将有助于我向自己保证:
- Yes, the insertion was done without errors, or
- No, the
0 1
indicates an error of some sort.
- 是的,插入没有错误,或者
- 不,这
0 1
表示某种错误。
If anyone has a link to the PostgreSQL doc which tells what these server response params are, I will study it... I have looked everywhere.
如果有人有 PostgreSQL 文档的链接,它告诉我这些服务器响应参数是什么,我会研究它......我到处找。
回答by Milen A. Radev
Excerpt from the relevant page in the manual:
摘自手册中的相关页面:
Outputs
On successful completion, an INSERT command returns a command tag of the form
INSERT oid count
The count is the number of rows inserted. If count is exactly one, and the target table has OIDs, then oid is the OID assigned to the inserted row. Otherwise oid is zero.
输出
成功完成后,INSERT 命令返回以下形式的命令标记
插入 oid 计数
计数是插入的行数。如果 count 正好是 1,并且目标表具有 OID,则 oid 是分配给插入行的 OID。否则 oid 为零。
回答by SamStephens
Annoyingly enough, I can't find any actual documentation about this.
令人讨厌的是,我找不到任何关于此的实际文档。
However looking at http://www.postgresql.org/docs/current/interactive/rules-status.htmland PQcmdStatus within http://www.postgresql.org/docs/current/interactive/libpq-exec.html, it appears that what you are seeing is a command status.
但是看着http://www.postgresql.org/docs/current/interactive/rules-status.html和PQcmdStatus内http://www.postgresql.org/docs/current/interactive/libpq-exec.html,它看来您所看到的是命令状态。
The format I'm inferring from the documentation is COMMAND
STATUS_CODE
ROWS_AFFECTED
.
我从文档中推断出的格式是COMMAND
STATUS_CODE
ROWS_AFFECTED
.
So what you are seeing is that you've done an insert, the status_code was zero, and one row was affected.
所以你看到的是你已经完成了一个插入,status_code 为零,一行受到影响。
So in other words, your command is completing successfully!
换句话说,您的命令已成功完成!