Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: return affectedRows for COPY command #480

Open
skyqrose opened this issue Dec 22, 2024 · 1 comment
Open

feature request: return affectedRows for COPY command #480

skyqrose opened this issue Dec 22, 2024 · 1 comment
Labels
good first issue Good for newcomers

Comments

@skyqrose
Copy link

I'm using a COPY command to load a csv, and want to know how many rows were added. Postgres does return this data (Postgres docs, see the Outputs section), but I can't access it via the PGlite API.

The query API Result includes a affectedRows field docs, but only for INSERT, UPDATE, and DELETE commands. (Side note: those docs could use a description of when the field is populated.)

I believe that this should be a simple addition, just adding a case to retrieveRowCount() for COPY.

My workaround for now is to make a separate SELECT count(*) query after doing the COPY.

@samwillis samwillis added the good first issue Good for newcomers label Dec 23, 2024
@samwillis
Copy link
Collaborator

Thanks for the report, quite right thats where to add it. This would be a great first contribution for someone, it's just an additional CASE on the switch branch along with UPDATE/DELETE:

function retrieveRowCount(msg: CommandCompleteMessage): number {
const parts = msg.text.split(' ')
switch (parts[0]) {
case 'INSERT':
return parseInt(parts[2], 10)
case 'UPDATE':
case 'DELETE':
return parseInt(parts[1], 10)
default:
return 0
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants