Thread: Please tell me about character code conversion.

Please tell me about character code conversion.

From
久門 愛
Date:
Hi,
Please tell me about character code conversion.
I am currently using Postgres 13.3.
I would like to set my own character code conversion as DEFAULT CONVERSION.
Since there is a CONVERSION provided by Postgres by default, the following
error will occur when executing CREATE CONVERSION.
-----------------------------
postgres=# CREATE DEFAULT CONVERSION pg_catalog.myconv_sjis_to_utf8 FOR
'SJIS' TO 'UTF8' FROM myconv_sjis_to_utf8;
ERROR:  default conversion for SJIS to UTF8 already exists 
postgres=#
-----------------------------

As a method to change the conversion provided by default, execute the
following SQL statement and after executing CREATE CONVERSION
I am trying to update the system catalog with an UPDATE statement. Is there
any problem with this method?
-----------------------------
CREATE CONVERSION pg_catalog.myconv_sjis_to_utf8 FOR 'SJIS' TO 'UTF8' FROM
myconv_sjis_to_utf8; 
UPDATE pg_conversion SET condefault='f' WHERE conname='sjis_to_utf8'; 
UPDATE pg_conversion SET condefault='t' WHERE conname='myconv_sjis_to_utf8';
-----------------------------

Thanks
Ai





Re: Please tell me about character code conversion.

From
Tom Lane
Date:
=?iso-2022-jp?B?GyRCNVdMZyEhMCYbKEI=?= <kumon.ai@ryobi.co.jp> writes:
> I would like to set my own character code conversion as DEFAULT CONVERSION.

That's not an area of functionality that ever got fleshed out completely.
What you're thinking about sounds like it'd work, but I'd strongly
suggest experimenting in a scratch database before doing it with
irreplaceable data.

Keep in mind also that pg_dump/pg_upgrade will absolutely not
reproduce this configuration for you.

            regards, tom lane