vscode-postgres icon indicating copy to clipboard operation
vscode-postgres copied to clipboard

Request: add ability to specify the encoding for the database

Open newdatasystems opened this issue 5 years ago • 5 comments

Running queries from vscode againsta database that isn't using the default (utf-8) encoding causes errors when pulling records that have special characters in them.

"invalid byte sequence for encoding: "UTF8": 0xe9 0x20 0x46

I looked for but couldn't find a way to configure the default encoding for a database for the plugin.

newdatasystems avatar Apr 12 '19 16:04 newdatasystems

Do you have an easy way I can reproduce this. (maybe a sample sql script I can run to setup and see the example)?

Borvik avatar Apr 12 '19 21:04 Borvik

It might be tough to do with a simple script. You'd need a database in a non-UTF8 encoding. Then you'd need to use special characters (for example non-english vowels) in the fields for that database. Let me see if I can set up an example.

newdatasystems avatar Apr 13 '19 17:04 newdatasystems

Perhaps a script with a CREATE DATABASE followed by a CREATE TABLE directive with single column, followed by a single INSERT with some of the offending characters.

Borvik avatar Apr 16 '19 10:04 Borvik

OK, yes, I was able to get that to work (or not work as the case might be)

-- create the database with the alternate encoding
CREATE DATABASE ascii_test
    WITH 
    OWNER = postgres
    ENCODING = 'SQL_ASCII'
    LC_COLLATE = 'English_United States.1252'
    LC_CTYPE = 'English_United States.1252'
    TABLESPACE = pg_default
    TEMPLATE = template0
    CONNECTION LIMIT = -1;

-- then from within that database add some records with special characters
CREATE TABLE public.test (Place serial, Name text);
INSERT INTO public.test (Name) VALUES ('Aliança Navegaçao');
INSERT INTO public.test (Name) VALUES ('Künhe');
INSERT INTO public.test (Name) VALUES ('Jørgen');

-- Each of these records return "Invalid byte sequence" errors when queried from vscode

newdatasystems avatar Apr 16 '19 12:04 newdatasystems

Thanks. I can repro with that now to figure out how best to handle it.

Borvik avatar Apr 16 '19 23:04 Borvik