¾�ΥС�������ʸ�� �� 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9.6 | 9.5 | 9.4 | 9.3 | 9.2 | 9.1 | 9.0 | 8.4 | 8.3 | 8.2 | 8.1 | 8.0 | 7.4 | 7.3 | 7.2

9.4. ʸ����ؿ��ȱ黻��

����Ǥ�ʸ������ͤ�Ĵ�������Τ���δؿ��ȱ黻�ҤˤĤ����������ޤ��� �����Ǥ�ʸ����Ȥ�character�ǡ�������character varying�ǡ������������text�ǡ��������ͤ�ޤߤޤ�����­�����Τʤ��¤ꡢ�����˵󤲤Ƥ������Ƥδؿ��Ϥ�������ƤΥǡ��������Ф��ƻ��ѤǤ��ޤ�����character�ǡ���������Ѥ�����硢��ưŪ�˶���ʸ�����ѥåɤ����Ȥ�������Ū���Ѥ�����ޤ��Τ����դ��Ƥ����������Х��ʥ���ǡ������ˤ������Ƥ�Ȥ�Ȥ���¸�ߤ��뤤���Ĥ��δؿ��⤢��ޤ���

SQL�Ǥϰ����ζ��ڤ�˥���ޤǤϤʤ�������ɤ���Ѥ���ʸ����ؿ��򤤤��Ĥ�������Ƥ��ޤ��� �ܺ٤ˤĤ��Ƥ�表9-5�򻲾Ȥ��Ƥ��������� �ޤ�PostgreSQL�ϡ������δؿ����Ф����̾�δؿ��ƤӽФ���ʸ����Ѥ���С��������󶡤��ޤ���表9-6�򻲾Ȥ��Ƥ��������ˡ�

注意: PostgreSQL 8.3�����ˤ����ơ������δؿ��Ϥ����Ĥ�����ʸ����ǡ��������ͤ�ٹ�ʤ��˼����դ����Τϡ������ǡ����������Ū��text���˶����������Ȥˤ��ޤ������ζ��������ˤ�ͽ�����ʤ�ư��θ����Ȥʤä��ΤǺ������ޤ�������������ʸ����Ϣ��黻�ҡ�||�ˤϰ����Ȥ���表9-5�Ǽ������褦�ˡ����ʤ��Ȥ�ҤȤĤ����Ϥ�ʸ���󷿤Ǥ���С���ʸ�������Ϥ�����դ��ޤ�������¾�ξ�硢������Ʊ��ư�����Ԥ���Τʤ顢text�ˤ�������Ū�������������Ƥ���������

表 9-5. SQLʸ����ؿ��ȱ黻��

�ؿ�����ͷ����������
string || string text ʸ������ 'Post' || 'greSQL'PostgreSQL
ʸ���� || ��ʸ���� �ޤ��ϡ� ��ʸ���� || ʸ���� text �ҤȤĤ���ʸ����Τ������Ϥ�ʸ������ 'Value: ' || 42Value: 42
bit_length(string)intʸ������Υӥåȿ�bit_length('jose')32
char_length(string) or character_length(string)int ʸ�������ʸ���� char_length('jose')4
lower(string)textʸ�����ʸ�����Ѵ�lower('TOM')tom
octet_length(string)intʸ������ΥХ��ȿ�octet_length('jose')4
overlay(string placing string from int [for int])text ��ʬʸ������ִ� overlay('Txxxxas' placing 'hom' from 2 for 4)Thomas
position(substring in string)int���ꤷ����ʬʸ����ξ��position('om' in 'Thomas')3
substring(string [from int] [for int])text ��ʬʸ����μ��Ф� substring('Thomas' from 2 for 3)hom
substring(string from pattern)text POSIX����ɽ���˰��פ�����ʸ�������Ф��ޤ����ѥ�����ޥå��˴ؤ��Ƥ��ܺ٤ϡ�項9.7�򻲾Ȥ��Ƥ��������� substring('Thomas' from '...$')mas
substring(string from pattern for escape)text SQL����ɽ���˰��פ�����ʬʸ�������Ф��ޤ����ѥ�����ޥå��˴ؤ��Ƥ��ܺ٤ϡ�項9.7�򻲾Ȥ��Ƥ��������� substring('Thomas' from '%#"o_a#"_' for '#')oma
trim([leading | trailing | both] [characters] from string) text characters�ʥǥե���ȤǤ϶���ˤǻ��ꤵ�줿ʸ���Τߤ�ޤ�Ǥ�Ĺ��ʸ�����string����Ƭ�������������Ƥ���ξ�����������ޤ��� trim(both 'x' from 'xTomxx')Tom
upper(string)textʸ�������ʸ�����Ѵ�upper('tom')TOM

����¾��表9-6����󤹤�ʸ�������ؿ����Ȥ��ޤ������Τ����Ĥ��ϡ�表9-5�ǰ�������ɸ��SQL��ʸ����ؿ���������뤿�ᡢ����Ū�˻��Ѥ���ޤ���

表 9-6. ����¾��ʸ����ؿ�

�ؿ�����ͷ����������
ascii(string)int �����κǽ��ʸ����ASCII�����ɡ�UTF8���Ф��Ƥ�ʸ����Unicode�����ɥݥ���Ȥ��֤��ޤ�������¾�Υޥ���Х�����沽�����ξ�硢������ASCIIʸ���Ǥʤ��ƤϤʤ�ޤ���NULL (0) ʸ���ϥƥ����ȥǡ����������Τ褦�ʥХ�������Ǽ�Ǥ��ʤ��Τ�ǧ����ޤ��� ascii('x')120
btrim(string text [, characters text])text characters�ʥǥե���Ȥ϶���ʸ���ˤǻ��ꤵ�줿ʸ���Τߤ�ͭ�����Ĺ��ʸ�����string����Ƭ���������������ޤ��� btrim('xyxtrimyyx', 'xy')trim
chr(int)text Ϳ����줿�����ɤ�ʸ����UTF8�Ǥϰ�����Unicode�����ɥݥ���ȤȤ��ư����ޤ�������¾�Υޥ���Х�����沽�����ǰ�����ASCIIʸ���Ǥ���ɬ�פ�����ޤ��� NULL (0)ʸ���ϥƥ����ȥǡ����������Τ褦�ʥХ��Ȥ��Ǽ���뤳�Ȥ��Ǥ��ʤ��Τǵ��Ĥ���ޤ��� chr(65)A
convert(string bytea, src_encoding name, dest_encoding name) bytea ʸ�����dest_encoding���Ѵ����ޤ���������沽������src_encoding�ǻ��ꤵ��ޤ���string�Ϥ�����沽������ͭ���Ǥʤ���Фʤ�ޤ����Ѵ���CREATE CONVERSION���������ޤ���ͭ�����Ѵ��ˤĤ��Ƥ�表9-7�򻲾Ȥ��Ƥ��������� convert('text_in_utf8', 'UTF8', 'LATIN1')Latin-1��ISO 8859-1����沽������text_in_utf8
convert_from(string bytea, src_encoding name) text �ǡ����١�������沽������ʸ������Ѵ����ޤ���������沽������src_encoding�ǻ��ꤵ��ޤ���string�Ϥ�����沽������ͭ���Ǥʤ���Фʤ�ޤ��� convert_from('text_in_utf8', 'UTF8')���ߤΥǡ����١�����沽������text_in_utf8
convert_to(string text, dest_encoding name) bytea ʸ�����dest_encoding���Ѵ����ޤ��� convert_to('some text', 'UTF8')UTF8��沽������some text
decode(string text, type text) bytea ������encode()����沽���줿string����Х��ʥ�ǡ��������椷�ޤ����ѥ�᡼���η���encode()��Ʊ���Ǥ��� decode('MTIzAAE=', 'base64')123\000\001
encode(data bytea, type text) text �Х��ʥ�ǡ�����ۤʤä�ɽ����������沽���ޤ������ݡ��Ȥ���Ƥ��뷿�ϡ�base64��hex��escape�Ǥ���escape��ñ�˥̥�Х��Ȥ�\000�Τ褦�˽��Ϥ����Хå�����å������Ų����ޤ��� encode(E'123\\000\\001', 'base64')MTIzAAE=
initcap(string)text ���줾���ñ������ʸ������ʸ���ˤ����Ĥ�Ͼ�ʸ���Τޤ޻Ĥ��ޤ���������ñ��Ȥϡ��ѿ����ʳ���ʸ���Ƕ��ڤ�줿���ѿ�������ʤ�ʸ�����¤ӤΤ��ȤǤ��� initcap('hi THOMAS')Hi Thomas
length(string)int string���ʸ���� length('jose')4
length(stringbytea, encoding name )int Ϳ����줿encoding�Ǥ�string���ʸ������string�Ϥ�����沽������ͭ���Ǥʤ���Фʤ�ޤ��� length('jose', 'UTF8')4
lpad(string text, length int [, fill text]) text ʸ��fill�ʥǥե���Ȥ϶���ʸ���ˤ�ʸ����������ɲä��ơ�string��length��Ĺ���ˤ��ޤ���string������length��Ĺ����Ķ���Ƥ�����ϡʱ�¦�����ڤ�ΤƤ��ޤ��� lpad('hi', 5, 'xy')xyxhi
ltrim(string text [, characters text]) text string�κǽ餫�顢characters�ʥǥե���Ȥϥ��ڡ����ˤǻ��ꤵ�줿ʸ��������ͭ�����Ĺ��ʸ����������ޤ��� ltrim('zzzytrim', 'xyz')trim
md5(string)text string��MD5�ϥå����׻�����16�ʿ��Ƿ�̤��֤��ޤ��� md5('abc')900150983cd24fb0 d6963f7d28e17f72
pg_client_encoding()name ���ߤΥ��饤����Ȥ���沽������̾���� pg_client_encoding()SQL_ASCII
quote_ident(string text)text Ϳ����줿ʸ�����SQL�䤤��碌ʸ����Ǽ��̻ҤȤ��ƻ��ѤǤ���褦�ˡ�Ŭ�ڤʰ�������դ����֤��ޤ���������ϡ�ɬ�פʾ����㤨�С�ʸ����˼��̻ҤȤ��ƻ��ѤǤ��ʤ�ʸ�����ޤޤ����䡢��ʸ���Ѵ��������ˤˤΤ��ɲä���ޤ��������ޤ줿������ϡ�Ŭ�ڤ���Ų�����ޤ��� 例38-1�⻲�Ȥ��Ƥ��������� quote_ident('Foo bar')"Foo bar"
quote_literal(string text)text Ϳ����줿ʸ�����SQL�䤤��碌ʸ�����ʸ����ƥ��Ȥ��ƻ��ѤǤ���褦�ˡ�Ŭ�ڤʰ�������դ����֤��ޤ��������ޤ줿ñ������䤪��ӥХå�����å���ϡ�Ŭ�ڤ���Ų�����ޤ��� quote_literal��NULL���Ϥ��Ф���NULL���֤����Ȥ����դ��Ƥ���������������NULL�Ȥʤ��ǽ���������硢���quote_nullable���������Ф���Ŭ���Ƥ��ޤ��� 例38-1�⻲�Ȥ��Ƥ��������� quote_literal('O\'Reilly')'O''Reilly'
quote_literal(value anyelement)text Ϳ����줿�ͤ�ƥ����Ȥ˶������������ƥ�ƥ��Ȥ��ư������դ����ޤ����Ȥ߹��ޤ줿��Ű�����ȵե���å����Ŭ�ڤ���Ų�����ޤ��� quote_literal(42.5)'42.5'
quote_nullable(string text)text Ϳ����줿ʸ�����SQL�䤤��碌ʸ�����ʸ����ƥ��Ȥ��ƻ��ѤǤ���褦�ˡ�Ŭ�ڤʰ�������դ����֤��ޤ��� �ޤ���������NULL�ξ�硢NULL���֤��ޤ��� �����ޤ줿ñ������䤪��ӥХå�����å����Ŭ�ڤ���Ų�����ޤ��� 例38-1�⻲�Ȥ��Ƥ��������� quote_nullable(NULL)NULL
quote_nullable(value anyelement)text Ϳ����줿�ͤ�ƥ����Ȥ˶������������ƥ�ƥ��Ȥ��ư������դ����ޤ��������Ǥʤ��ȡ�������NULL�ξ���NULL���֤��ޤ��������ޤ줿ñ�������ȥХå�����å����Ŭ�ڤ���Ų�����ޤ��� quote_nullable(42.5)'42.5'
regexp_matches(string text, pattern text [, flags text])setof text[] string���Ф���POSIX����ɽ���ǥޥå�������ª���줿���٤Ƥ���ʬʸ������֤��ޤ������ܺ٤�項9.7.3�򻲾Ȥ��Ƥ��������� regexp_matches('foobarbequebaz', '(bar)(beque)'){bar,beque}
regexp_replace(string text, pattern text, replacement text [, flags text])text POSIX����ɽ���˰��פ�����ʬʸ������ִ����ޤ������ܺ٤�項9.7.3�򻲾Ȥ��Ƥ��������� regexp_replace('Thomas', '.[mN]a.', 'M')ThM
regexp_split_to_array(string text, pattern text [, flags text ])text[] POSIX����ɽ������ڤ�ʸ���˻Ȥä�string��ʬ�䤷�ޤ����ܤ�����項9.7.3�򻲾Ȥ��������� regexp_split_to_array('hello world', E'\\s+'){hello,world}
regexp_split_to_table(string text, pattern text [, flags text])setof text POSIX����ɽ������ڤ�ʸ���˻Ȥä�string��ʬ�䤷�ޤ����ܤ�����項9.7.3�򻲾Ȥ��������� regexp_split_to_table('hello world', E'\\s+')hello

world

(2 rows)
repeat(string text, number int)text���ꤵ�줿number�ο�����string�򷫤��֤��ޤ���repeat('Pg', 4)PgPgPgPg
replace(string text, from text, to text)textstring�˽и��������Ƥ�from��ʬʸ�����to��ʬʸ������ִ����ޤ��� replace('abcdefabcdef', 'cd', 'XX')abXXefabXXef
rpad(string text, length int [, fill text]) text ʸ��fill�ʥǥե���Ȥϥ��ڡ����ˤ�ʸ������ɲä��ơ�string��length��Ĺ���ˤ��ޤ���string������length��Ĺ����Ķ���Ƥ�������ڤ�ΤƤ��ޤ��� rpad('hi', 5, 'xy')hixyx
rtrim(string text [, characters text]) text string���������顢characters�ʥǥե���Ȥϥ��ڡ����ˤǻ��ꤵ�줿ʸ���Τߤ�ͭ�����Ĺ��ʸ����������ޤ��� rtrim('trimxxxx', 'x')trim
split_part(string text, delimiter text, field int)textstring��delimiter��ʬ�䤷�����η�̤����1����Ϥޤ�褦�˿�����˻��ꤷ���ե�����ɤ��֤��ޤ��� split_part('abc~@~def~@~ghi', '~@~', 2)def
strpos(string, substring)int ���ꤷ����ʬʸ����ΰ��֤����ꤷ�ޤ���position(substring in string) ��Ʊ���Ǥ����������ν�����դˤʤäƤ��뤳�Ȥ����դ��Ƥ��������ˡ� strpos('high', 'ig')2
substr(string, from [, count])text ���ꤷ����ʬʸ�������Ф��ޤ���substring(string from from for count)��Ʊ���Ǥ��ˡ� substr('alphabet', 3, 2)ph
to_ascii(string text [, encoding text])text string��¾����沽��������ASCII���Ѵ����ޤ���LATIN1��LATIN2��LATIN9��WIN1250��沽����������Ѵ��Τߤ򥵥ݡ��Ȥ��ޤ����� to_ascii('Karel')Karel
to_hex(number int or bigint)textnumber��Ʊ����16�ʿ�ɽ�����Ѵ����ޤ��� to_hex(2147483647)7fffffff
translate(string text, from text, to text) text from����ǻ��ꤵ�줿ʸ���Ȱ��פ���string�ˤ������Ƥ�ʸ���ϡ�������б�����to�ǻ��ꤵ�줿ʸ�����֤��������ޤ��� set translate('12345', '14', 'ax')a23x5

表 9-7. Built-in Conversions

�Ѵ�̾ [a] �Ѵ�������沽�����Ѵ������沽����
ascii_to_micSQL_ASCIIMULE_INTERNAL
ascii_to_utf8SQL_ASCIIUTF8
big5_to_euc_twBIG5EUC_TW
big5_to_micBIG5MULE_INTERNAL
big5_to_utf8BIG5UTF8
euc_cn_to_micEUC_CNMULE_INTERNAL
euc_cn_to_utf8EUC_CNUTF8
euc_jp_to_micEUC_JPMULE_INTERNAL
euc_jp_to_sjisEUC_JPSJIS
euc_jp_to_utf8EUC_JPUTF8
euc_kr_to_micEUC_KRMULE_INTERNAL
euc_kr_to_utf8EUC_KRUTF8
euc_tw_to_big5EUC_TWBIG5
euc_tw_to_micEUC_TWMULE_INTERNAL
euc_tw_to_utf8EUC_TWUTF8
gb18030_to_utf8GB18030UTF8
gbk_to_utf8GBKUTF8
iso_8859_10_to_utf8LATIN6UTF8
iso_8859_13_to_utf8LATIN7UTF8
iso_8859_14_to_utf8LATIN8UTF8
iso_8859_15_to_utf8LATIN9UTF8
iso_8859_16_to_utf8LATIN10UTF8
iso_8859_1_to_micLATIN1MULE_INTERNAL
iso_8859_1_to_utf8LATIN1UTF8
iso_8859_2_to_micLATIN2MULE_INTERNAL
iso_8859_2_to_utf8LATIN2UTF8
iso_8859_2_to_windows_1250LATIN2WIN1250
iso_8859_3_to_micLATIN3MULE_INTERNAL
iso_8859_3_to_utf8LATIN3UTF8
iso_8859_4_to_micLATIN4MULE_INTERNAL
iso_8859_4_to_utf8LATIN4UTF8
iso_8859_5_to_koi8_rISO_8859_5KOI8R
iso_8859_5_to_micISO_8859_5MULE_INTERNAL
iso_8859_5_to_utf8ISO_8859_5UTF8
iso_8859_5_to_windows_1251ISO_8859_5WIN1251
iso_8859_5_to_windows_866ISO_8859_5WIN866
iso_8859_6_to_utf8ISO_8859_6UTF8
iso_8859_7_to_utf8ISO_8859_7UTF8
iso_8859_8_to_utf8ISO_8859_8UTF8
iso_8859_9_to_utf8LATIN5UTF8
johab_to_utf8JOHABUTF8
koi8_r_to_iso_8859_5KOI8RISO_8859_5
koi8_r_to_micKOI8RMULE_INTERNAL
koi8_r_to_utf8KOI8RUTF8
koi8_r_to_windows_1251KOI8RWIN1251
koi8_r_to_windows_866KOI8RWIN866
koi8_u_to_utf8KOI8UUTF8
mic_to_asciiMULE_INTERNALSQL_ASCII
mic_to_big5MULE_INTERNALBIG5
mic_to_euc_cnMULE_INTERNALEUC_CN
mic_to_euc_jpMULE_INTERNALEUC_JP
mic_to_euc_krMULE_INTERNALEUC_KR
mic_to_euc_twMULE_INTERNALEUC_TW
mic_to_iso_8859_1MULE_INTERNALLATIN1
mic_to_iso_8859_2MULE_INTERNALLATIN2
mic_to_iso_8859_3MULE_INTERNALLATIN3
mic_to_iso_8859_4MULE_INTERNALLATIN4
mic_to_iso_8859_5MULE_INTERNALISO_8859_5
mic_to_koi8_rMULE_INTERNALKOI8R
mic_to_sjisMULE_INTERNALSJIS
mic_to_windows_1250MULE_INTERNALWIN1250
mic_to_windows_1251MULE_INTERNALWIN1251
mic_to_windows_866MULE_INTERNALWIN866
sjis_to_euc_jpSJISEUC_JP
sjis_to_micSJISMULE_INTERNAL
sjis_to_utf8SJISUTF8
tcvn_to_utf8WIN1258UTF8
uhc_to_utf8UHCUTF8
utf8_to_asciiUTF8SQL_ASCII
utf8_to_big5UTF8BIG5
utf8_to_euc_cnUTF8EUC_CN
utf8_to_euc_jpUTF8EUC_JP
utf8_to_euc_krUTF8EUC_KR
utf8_to_euc_twUTF8EUC_TW
utf8_to_gb18030UTF8GB18030
utf8_to_gbkUTF8GBK
utf8_to_iso_8859_1UTF8LATIN1
utf8_to_iso_8859_10UTF8LATIN6
utf8_to_iso_8859_13UTF8LATIN7
utf8_to_iso_8859_14UTF8LATIN8
utf8_to_iso_8859_15UTF8LATIN9
utf8_to_iso_8859_16UTF8LATIN10
utf8_to_iso_8859_2UTF8LATIN2
utf8_to_iso_8859_3UTF8LATIN3
utf8_to_iso_8859_4UTF8LATIN4
utf8_to_iso_8859_5UTF8ISO_8859_5
utf8_to_iso_8859_6UTF8ISO_8859_6
utf8_to_iso_8859_7UTF8ISO_8859_7
utf8_to_iso_8859_8UTF8ISO_8859_8
utf8_to_iso_8859_9UTF8LATIN5
utf8_to_johabUTF8JOHAB
utf8_to_koi8_rUTF8KOI8R
utf8_to_koi8_uUTF8KOI8U
utf8_to_sjisUTF8SJIS
utf8_to_tcvnUTF8WIN1258
utf8_to_uhcUTF8UHC
utf8_to_windows_1250UTF8WIN1250
utf8_to_windows_1251UTF8WIN1251
utf8_to_windows_1252UTF8WIN1252
utf8_to_windows_1253UTF8WIN1253
utf8_to_windows_1254UTF8WIN1254
utf8_to_windows_1255UTF8WIN1255
utf8_to_windows_1256UTF8WIN1256
utf8_to_windows_1257UTF8WIN1257
utf8_to_windows_866UTF8WIN866
utf8_to_windows_874UTF8WIN874
windows_1250_to_iso_8859_2WIN1250LATIN2
windows_1250_to_micWIN1250MULE_INTERNAL
windows_1250_to_utf8WIN1250UTF8
windows_1251_to_iso_8859_5WIN1251ISO_8859_5
windows_1251_to_koi8_rWIN1251KOI8R
windows_1251_to_micWIN1251MULE_INTERNAL
windows_1251_to_utf8WIN1251UTF8
windows_1251_to_windows_866WIN1251WIN866
windows_1252_to_utf8WIN1252UTF8
windows_1256_to_utf8WIN1256UTF8
windows_866_to_iso_8859_5WIN866ISO_8859_5
windows_866_to_koi8_rWIN866KOI8R
windows_866_to_micWIN866MULE_INTERNAL
windows_866_to_utf8WIN866UTF8
windows_866_to_windows_1251WIN866WIN
windows_874_to_utf8WIN874UTF8
euc_jis_2004_to_utf8EUC_JIS_2004UTF8
ut8_to_euc_jis_2004UTF8EUC_JIS_2004
shift_jis_2004_to_utf8SHIFT_JIS_2004UTF8
ut8_to_shift_jis_2004UTF8SHIFT_JIS_2004
euc_jis_2004_to_shift_jis_2004EUC_JIS_2004SHIFT_JIS_2004
shift_jis_2004_to_euc_jis_2004SHIFT_JIS_2004EUC_JIS_2004
注意:
a. �Ѵ�̾�ϡ�ɸ��̿̾�ηϤ˽��äƤ��ޤ����Ѵ�����沽�����θ���̾���⡢�ѿ����ʳ���ʸ���򥢥�������������֤����������θ��_to_���դ����������Ѵ�����沽����̾��Ʊ�ͤ˽���������Τ�³������ΤǤ����������äơ�������̾�Τϴ���Ū�ʥ�����̾�Ȥϰۤʤ��ǽ��������ޤ���