Re: Using psql -f to load a UTF8 file

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: Alan Millington <admillington(at)yahoo(dot)co(dot)uk>
Cc: Leif Biberg Kristensen <leif(at)solumslekt(dot)org>, Postgres general mailing list <pgsql-general(at)postgresql(dot)org>
Subject: Re: Using psql -f to load a UTF8 file
Date: 2012-09-21 14:32:35
Message-ID: 505C7A83.7000108@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 09/20/2012 10:27 AM, Alan Millington wrote:
> Thank you for the link. I am using Notepad, which inserts the byte order
> mark. Following the links a bit further, I gather that the version of
> Notepad that I am using may not identify a UTF8 file correctly if the
> byte order mark is omitted. Also, as I mentioned, Python makes use of
> it. (From the Python documentation on Encoding declarations: "If the
> first bytes of the file are the UTF-8 byte-order mark ('\xef\xbb\xbf'),
> the declared file encoding is UTF-8 (this is supported, among others, by
> Microsoft’s Notepad).")
> The conclusion seems to be that I must use one editor for Python, and
> another for Postgres.

The problem is Notepad has a limited view of the text world. If you use
it only in the Microsoft universe and for simple tasks it is sufficient.
The issues arise when you try to work with files outside that scope. For
long term peace of mind you will better served by more capable text
editors(see other posts for suggestions). As to the Python
documentation, it goes on to say:

http://docs.python.org/tutorial/interpreter.html#source-code-encoding

"Notice that this signature is not understood in older Python releases
(2.2 and earlier), and also not understood by the operating system for
script files with #! lines (only used on Unix systems)."

From the Zen of Python:
"Explicit is better than implicit"

Following that the preferred way of declaring an encoding would be:
# -*- coding: utf-8 -*-

See the above link for more information.
>

--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message salah jubeh 2012-09-21 14:32:55 9.1 vs 8.4 performance
Previous Message Merlin Moncure 2012-09-21 13:04:56 Re: Expression to construct a anonymous record with named columns?