Skip to content

Better exception on COPY API confusion #1673

Closed

Description

@ManeSi

I want to add datas from a csv file into the table tbl_test. This table has no relation, so that it is very easy.
I created my table as following via the SQL-Shell:

CREATE TABLE tbl_test(
id SERIAL PRIMARY KEY NOT NULL,
value INT
);

The Content of my csv file is very Basic:

value
123
234
345
456

No I have a test SUB in Visual Basic .net with the following Content

Public Sub Insert_Into_tbl_Test()
Try
       Using conn = New NpgsqlConnection("Host=" & c_dbHost & ";Username=" & c_user   & ";Password=" & c_password & ";Database=" & c_DBName)
       conn.Open()
            Using writer = conn.BeginTextImport("COPY tbl_test(value) FROM 'C:\temp\test.csv' DELIMITER ',' CSV HEADER;")
            End Using
        End Using

 Catch ex As Exception
   Console.WriteLine("")
   MessageBox.Show(ex.Message)
 End Try
End Sub

Exception message:
Received unexpected backend message CompletedResponse. Please file a bug.

Further technical details

Npgsql version: 3.2.5
PostgreSQL version: 9.6.2
Operating system: Windows 7 Enterprise, Service Pack 1
Programming Tool: Visual Studio Professional 2013 Version 12.0.40629.00 Update 5
Language: Visual Basic

Activity

  1. roji commented on Sep 22, 2017

    @roji
    Member

    If you have your CSV file on the client side (where the Npgsql app is running), then you should be using COPY tbl_test(value) FROM STDIN, not FROM c:\temp\test.csv. The latter is used when the csv file is on the PostgreSQL server. See the documentation.

    If you simply want to import a file present on your server, just execute the COPY command as a regular SQL - create a command and execute it with ExecuteNonQuery. Don't use the BeginTextImport API.

    Will keep open to fix the error though.

  2. self-assigned this
    on Oct 8, 2017
  3. added this to the 3.2.6 milestone on Oct 8, 2017
  4. added a commit that references this issue on Oct 8, 2017
    37eb753
  5. changed the title [-]COPY command: Received unexpected backend message CompletedResponse[/-] [+]Better exception on COPY API confusion[/+] on Oct 8, 2017
  6. ManeSi commented on Oct 9, 2017

    @ManeSi
    Author

    Thanks for your efforts!

  7. added theissue type on Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions