NpgSQL insert file path containing backslashes "\\"
- by Chau
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?