NpgSQL insert file path containing backslashes "\\"

Posted by Chau on Stack Overflow See other posts from Stack Overflow or by Chau
Published on 2010-03-22T15:33:17Z Indexed on 2010/03/23 16:53 UTC
Read the original article Hit count: 511

I am trying to create a record containing the path to a file. The insertion is done into a Postgres database where UTF8 is enabled, using the NpqSQL driver.

My table definition:

CREATE TABLE images
(
    id serial,
    file_location character varying NOT NULL
)

My SQL statement (boiled down to a minimum):

INSERT INTO images (file_location) VALUES (E'\\2010')

When using pgAdmin to insert the above statement, it works fine. Using the NpgSQL driver through Visual Studio C#, it fails with this exception:

"ERROR: 22021: invalid byte sequence for encoding \"UTF8\": 0x81"

Replacing my SQL statement with the following:

INSERT INTO images (file_location) VALUES (E'\\a2010')
                                               ^

The E is encouraged by pgAdmin when using double backslashes.

So a quick recap: Why is NpqSQL stopping my insertion of the \\2010?

© Stack Overflow or respective owner

Related posts about npgsql

Related posts about postgresql