Get row count from COPY command

When copying data from a file, you get the number of lines in psql using the "command tag":

db=# COPY t FROM '/var/lib/postgres/test.sql'; COPY 10 

I need the number of rows and would like to avoid the excess count() in the table.

Is there a way to get this score from COPY directly in the PL / pgSQL function?
As far as I know, they are not, but maybe I'm missing something?

For PostgreSQL 9.2. But any option in any version will be of interest.

+4
source share
1 answer

Not in PG 9.2, but in PG 9.3 it is kindly provided by Paul (E 1.3.1.7):

Allow PL / pgSQL access to the number of rows processed by COPY (Pavel Stehule)

GET DIAGNOSTICS x = ROW_COUNT Command.

http://www.postgresql.org/docs/devel/static/release-9-3.html

+7
source

Source: https://habr.com/ru/post/1481389/


All Articles