Skip to content

Instantly share code, notes, and snippets.

@noborus
Created March 10, 2014 05:36
Show Gist options
  • Save noborus/9460008 to your computer and use it in GitHub Desktop.
Save noborus/9460008 to your computer and use it in GitHub Desktop.
SELECT '0x' ||
encode(substr(s.word::text,generate_series(1,length(s.word::text),1),1)::bytea, 'hex') AS code,
substr(s.word::text,generate_series(1,length(s.word::text),1),1) AS char
FROM
(SELECT '漢字' AS word) AS s;
code | char
----------+------
0xe6bca2 | 漢
0xe5ad97 | 字
(2 rows)
@noborus
Copy link
Author

noborus commented Mar 10, 2014

SELECT '0x'||encode(char::bytea, 'hex') AS code, char
FROM
(SELECT regexp_split_to_table('漢字', '') AS char) AS w;

こっちのが短かい。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment