diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2012-10-03 14:32:01 +0300 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2012-10-03 14:38:22 +0300 |
commit | 7ae1815961c635fd1a6fe72acb89fdef741a45a8 (patch) | |
tree | e72e73802bc89839172130e5f9b741e3d585542f /src/backend | |
parent | bc1229c83238a0d71a3923cb48e53ea7ea37654c (diff) | |
download | postgresql-7ae1815961c635fd1a6fe72acb89fdef741a45a8.tar.gz postgresql-7ae1815961c635fd1a6fe72acb89fdef741a45a8.zip |
Return the number of rows processed when COPY is executed through SPI.
You can now get the number of rows processed by a COPY statement in a
PL/pgSQL function with "GET DIAGNOSTICS x = ROW_COUNT".
Pavel Stehule, reviewed by Amit Kapila, with some editing by me.
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/executor/spi.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c index 70d60049050..bf8c4c71136 100644 --- a/src/backend/executor/spi.c +++ b/src/backend/executor/spi.c @@ -1922,25 +1922,31 @@ _SPI_execute_plan(SPIPlanPtr plan, ParamListInfo paramLI, _SPI_current->processed = _SPI_current->tuptable->alloced - _SPI_current->tuptable->free; + res = SPI_OK_UTILITY; + /* - * CREATE TABLE AS is a messy special case for historical - * reasons. We must set _SPI_current->processed even though - * the tuples weren't returned to the caller, and we must - * return a special result code if the statement was spelled - * SELECT INTO. + * Some utility statements return a row count, even though the + * tuples are not returned to the caller. */ if (IsA(stmt, CreateTableAsStmt)) { Assert(strncmp(completionTag, "SELECT ", 7) == 0); _SPI_current->processed = strtoul(completionTag + 7, NULL, 10); + + /* + * For historical reasons, if CREATE TABLE AS was spelled + * as SELECT INTO, return a special return code. + */ if (((CreateTableAsStmt *) stmt)->is_select_into) res = SPI_OK_SELINTO; - else - res = SPI_OK_UTILITY; } - else - res = SPI_OK_UTILITY; + else if (IsA(stmt, CopyStmt)) + { + Assert(strncmp(completionTag, "COPY ", 5) == 0); + _SPI_current->processed = strtoul(completionTag + 5, + NULL, 10); + } } /* |