Skip site navigation (1) Skip section navigation (2)

Re: libpq + utf-8

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Ло тин Константин СергекBBF <lokhtin(at)irkutsk(dot)bnk(dot)ru>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: libpq + utf-8
Date: 2007-08-15 03:52:15
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-interfaces
On Wed, Aug 15, 2007 at 10:23:08AM +0900, Лохтин Константин Сергеевич wrote:
> I met problems using libpq API with utf-8 database.
> I can't figure out how to use, for example, function PQexec. This function
> has two parameters: PQexec(PGconn *conn, const char *command);
> If the command is, for example:
>   INSERT INTO mytable (column1,column2,column3) VALUES ('non-English text 1','non-English text 2','non-English text 3')
> what format the string command[] should have? Should it be UTF-8, UTF-16 or ANSI(??) string?

The string should be in the encoding specified by client_encoding.
The default is the same as the database encoding but the setting
can be changed with a "SET client_encoding" statement or via the
PGCLIENTENCODING environment variable.

> When I use INSERT command with English data I can use ANSI string as
> command[] parameter and everything works fine, but when I try to
> INSERT, for example, Russian text into table columns, I fail using
> both UTF-8 and Windows1251 encoding in command[].

I can successfully insert Cyrillic text into a UTF-8 database using
PQexec().  I tested with both UTF-8 and Windows-1251 strings after
setting client_encoding appropriately.

What error or unexpected behavior are you getting?  What's the
output of "SHOW client_encoding"?  What version of PostgreSQL are
you running?  Can you post a simple program that demonstrates the

Michael Fuhr

In response to

  • libpq + utf-8 at 2007-08-15 01:23:08 from Лохтин Константин Сергеевич

pgsql-interfaces by date

Next:From: Stephen DaviesDate: 2007-08-18 06:40:28
Subject: Query performance
Previous:From: Лохтин Константин СергеевичDate: 2007-08-15 01:23:08
Subject: libpq + utf-8

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group