tds-fdw / tds_fdw

A PostgreSQL foreign data wrapper to connect to TDS databases (Sybase and Microsoft SQL Server)
Other
381 stars 102 forks source link

'utf-8' codec can't decode byte ERROR when querying data #202

Closed jaitor1 closed 5 years ago

jaitor1 commented 5 years ago

I have created this foreign server:

CREATE SERVER servprod_sqlprod_mydb
FOREIGN DATA WRAPPER tds_fdw 
OPTIONS (servername 'XX.XX.XX.XX', port '1501',msg_handler 'notice', database 'WHATEVER');

CREATE USER MAPPING FOR postgres
    SERVER servprod_sqlprod_mydb
    OPTIONS (username 'xxx', password 'xxxxxxxxxx');

CREATE FOREIGN TABLE tds_test (
    caclamun character varying,
    caclacal character varying,
    catipvia character varying,
    cadescri character varying,
    caidenti character varying,
    cafechal character varying,
    cafechba character varying)
    SERVER servprod_sqlprod_mydb
    OPTIONS (table_name 'dbo.MYSQL TABLE');

When opening the table I am getting:

'utf-8' codec can't decode byte 0xd1 in position 4: invalid continuation byte

jaitor1 commented 5 years ago

I fixed the problem adding character_set 'UTF-8' when creating foreign server. Example:

CREATE SERVER myserver 
FOREIGN DATA WRAPPER tds_fdw 
OPTIONS (servername 'localhost', port '1501',msg_handler 'notice', database 'mydb', character_set 'UTF-8');