开发者

SQL Server generated "Text File" data importing in to postgressql using copy command

I have one text file generated using SQL Server 2005. While I am importing the text file into one of my PostgreSQL table using "copy" it is giving me the following error:

ERROR: invalid byte sequence for encoding "UTF8": 0xf开发者_JS百科f

Can any one tell me what i need to do get the data from SQL Server 2005 to PostgreSQL?


I had exactly the same situation (except for SQL Server 2008 instead of 2005). When I was exporting the file using 'SQL Server Import and Export Wizard' and picked Flat File as Destination, the 'Code page' parameter defaulted to '1252 (ANSI - Latin I)'. Thus, when running copy command in postgreSQL I used set client_encoding to 'LATIN1'; copy tablename FROM 'path/to/file.csv' DELIMITERS '|' CSV; - and it executed successfully.


If the file is indeeded in Windows-1252 encoding then you can switch the encoding by using set client_encoding=windows_1252 before running the copy command.

Check out the manual for a list of available encodings:
http://www.postgresql.org/docs/9.0/static/multibyte.html


SQL Server text output (BCP files?) have in the past been written as UTF-16, which is a Unicode encoding that PostgreSQL doesn't support. UTF-16 files start with 0xff 0xfe (or 0xfe 0xff) so that would be one reason for getting a complaint about that particular byte value first.

On Linux or similar I'd suggest using the "recode" or "iconv" utilities to convert from UTF-16 to UTF-8, which is PostgreSQL's preferred all-Unicode encoding. One recommendation for performing that task on Windows is just to get a Windows version of recode: UTF-16 to UTF-8 conversion (for scripting in Windows)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜