{"id":1148,"date":"2011-08-05T17:24:40","date_gmt":"2011-08-05T08:24:40","guid":{"rendered":"http:\/\/www.lancard.com\/blog\/?p=1148"},"modified":"2025-03-12T11:30:51","modified_gmt":"2025-03-12T02:30:51","slug":"%e6%ad%a3%e8%a6%8f%e5%8c%96%e3%81%97%e3%81%aa%e3%81%84%e3%81%a8%e9%a7%84%e7%9b%ae%e3%81%8b%e3%81%aa","status":"publish","type":"post","link":"https:\/\/www.lancard.com\/blog\/2011\/08\/05\/%e6%ad%a3%e8%a6%8f%e5%8c%96%e3%81%97%e3%81%aa%e3%81%84%e3%81%a8%e9%a7%84%e7%9b%ae%e3%81%8b%e3%81%aa\/","title":{"rendered":"\u6b63\u898f\u5316\u3057\u306a\u3044\u3068\u99c4\u76ee\u304b\u306a"},"content":{"rendered":"<p>PostgreSQL8.1\u3092\u4f7f\u3063\u305f\u3042\u308b\u30b7\u30b9\u30c6\u30e0\u3067\u306e\u304a\u8a71\u3057\u3067\u3059\u3002<\/p>\n<p>\u307e\u305a\u30e6\u30fc\u30b6\u30c7\u30fc\u30bf\u306e\u30c6\u30fc\u30d6\u30eb\u304c\u6709\u308a\u3001\u305d\u306e\u30e6\u30fc\u30b6\u306fID\uff08\u9023\u756a\uff09\u3067\u7ba1\u7406\u3055\u308c\u3066\u3044\u307e\u3059\u3002<br \/>\n\u305d\u3057\u3066\u30e6\u30fc\u30b6\u304c\u767b\u9332\u3059\u308b\u30c7\u30fc\u30bf\u30c6\u30fc\u30d6\u30eb\u306b\u306f\u3001\u30c7\u30fc\u30bf\u3054\u3068\u306b\u305d\u306e\u30c7\u30fc\u30bf\u3092\u5171\u6709\u3059\u308b\u30e6\u30fc\u30b6\u306eID\u304c\u8907\u6570\u767b\u9332\u3055\u308c\u3066\u3044\u307e\u3059\u3002<br \/>\n\u3053\u308c\u306f\u30e6\u30fc\u30b6ID\u3092CSV\u5f62\u5f0f\u306e\u6587\u5b57\u5217\u3067\u683c\u7d0d\u3092\u3057\u3066\u3044\u308b\u3093\u3067\u3059\u304c\u3001\u6761\u4ef6\u6587\u3067LIKE\u3068OR\u3092\u9023\u767a\u3059\u308b\u306e\u3067\u30c7\u30fc\u30bf\u91cf\u304c\u591a\u304f\u306a\u308b\u3068\u691c\u7d22\u304c\u975e\u5e38\u306b\u91cd\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u6b63\u898f\u5316\u3057\u306a\u3044\u3068\u99c4\u76ee\u304b\u306a\u3068\u8003\u3048\u305f\u3093\u3067\u3059\u304c\u3001\u5bfe\u8c61\u3068\u306a\u308b\u30c6\u30fc\u30d6\u30eb\u304c\u8907\u6570\u6709\u308b\u306e\u3067\u4fee\u6b63\u306b\u5fc5\u8981\u306a\u7b87\u6240\u304c\u6563\u5728\u3057\u3066\u3044\u3066\u3001\u305d\u306e\u3046\u3048\u30c7\u30fc\u30bf\u91cf\u304c\u591a\u304f\u306a\u308b\u30c6\u30fc\u30d6\u30eb\u306f\uff11\u3064\u304b\uff12\u3064\u3057\u304b\u306a\u3044\u306e\u3067\u3001\u69cb\u9020\u3092\u5909\u3048\u305a\u306b\u3069\u3046\u306b\u304b\u306a\u3089\u306a\u3044\u304b\u3068\u5225\u306e\u65b9\u6cd5\u3092\u63a2\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u7d50\u679c\u3068\u3057\u3066\u4e00\u5fdc\u3001postgresql-contrib\u306b\u542b\u307e\u308c\u308btsearch2\u304c\u3001\u5206\u304b\u3061\u66f8\u304d\u5f62\u5f0f\u306e\u5168\u6587\u691c\u7d22\u304c\u51fa\u6765\u308b\u306e\u3067\u826f\u3044\u611f\u3058\u304b\u306a\u3068\u8a00\u3046\u4e8b\u3067\u3084\u3063\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\n\u65e5\u672c\u8a9e\u306b\u306f\u5bfe\u5fdc\u3057\u3066\u3044\u307e\u305b\u3093\u304c\u3001\u4eca\u56de\u306f\u4e0d\u8981\u306a\u306e\u3067\u69cb\u3044\u307e\u305b\u3093\u3002<br \/>\n\uff08GIN\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306f\u5bfe\u5fdc\u304c8.2\u304b\u3089\u3060\u3063\u305f\u306e\u3067\u30d1\u30b9\u3057\u307e\u3057\u305f\uff09<\/p>\n<p>postgresql-contrib\u306f\u65e2\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001postgres\u30e6\u30fc\u30b6\u306b\u306a\u3063\u3066\u3001<br \/>\n<code>psql dbname -f \/usr\/share\/pgsql\/contrib\/tsearch2.sql<\/code><\/p>\n<p>\u6b21\u306bpsql dbname\u3067\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u3001GRANT\u3092\u639b\u3051\u307e\u3059\u3002<br \/>\n<code>GRANT ALL ON pg_ts_cfg TO PUBLIC;<br \/>\nGRANT ALL ON pg_ts_cfgmap TO PUBLIC;<br \/>\nGRANT ALL ON pg_ts_dict TO PUBLIC;<br \/>\nGRANT ALL ON pg_ts_parser TO PUBLIC;<\/code><\/p>\n<p>\u3068\u308a\u3042\u3048\u305a\u30c6\u30b9\u30c8\u3002<br \/>\n<code>CREATE TABLE test_tb(testts tsvector);<br \/>\nCREATE INDEX test_tb_testts ON test_tb USING gist (testts);<\/code><\/p>\n<p>\u4f55\u4e8b\u3082\u306a\u304f\u4f5c\u6210\u3055\u308c\u305f\u306e\u3067\u3001\u30c7\u30fc\u30bf\u3092\u5165\u308c\u3066\u307f\u3066\u3001SELECT\u3002<br \/>\n\u30c7\u30fc\u30bf\u4e2d\u306b2\u30684\u306e\u542b\u307e\u308c\u308b\u30c7\u30fc\u30bf\u3092\u691c\u7d22\u3057\u307e\u3059\u3002<br \/>\n<code>SELECT * FROM test_tb WHERE testts @@ to_tsquery('default', '2&amp;4'); -- and\u691c\u7d22<br \/>\nSELECT * FROM test_tb WHERE testts @@ to_tsquery('default', '2|4'); -- or\u691c\u7d22<\/code><\/p>\n<p>EXPLAIN\u3059\u308b\u3068\u3001INDEX\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002<br \/>\nBitmap Heap Scan on test_tb (cost=4.10..108.72 rows=27 width=32)<br \/>\nFilter: (testts @@ &#8221;&#8217;2&#8221; &amp; &#8221;4&#8221;&#8217;::tsquery)<br \/>\n-&gt; Bitmap Index Scan on test_tb_index (cost=0.00..4.10 rows=27 width=0)<br \/>\nIndex Cond: (testts @@ &#8221;&#8217;2&#8221; &amp; &#8221;4&#8221;&#8217;::tsquery)<\/p>\n<p>\u3053\u308c\u3092\u5fdc\u7528\u3057\u3066\u3001\u5bfe\u8c61\u3068\u306a\u308bhoge\u30c6\u30fc\u30d6\u30eb\u306ecol\u5217\u306btsvector\u578b\u306b\u5bfe\u5fdc\u3055\u305b\u305f\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<br \/>\n\u4e00\u5fdc\u30ab\u30f3\u30de\u304b\u3089\u30b9\u30da\u30fc\u30b9\u306b\u5909\u66f4\u3057\u3066\u3001\u683c\u7d0d\u3059\u308b\u3088\u3046\u306breplace\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n<code>CREATE INDEX hoge_col ON hoge USING gist (to_tsvector('default', replace(col,',',' ')));<br \/>\nSELECT * FROM hoge WHERE to_tsvector('default', replace(col,',',' ')) @@ to_tsquery('default', '2|4');<\/code><\/p>\n<p>\u3053\u308c\u3067\u4e00\u5fdc\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306f\u52b9\u3044\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002<br \/>\n\u4eca\u307e\u3067\u306e\u30af\u30a8\u30ea\u306f\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u4f7f\u308f\u306a\u3044\u3067\u305d\u306e\u307e\u307e\u4f7f\u3048\u308b\u3057\u3001\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u30b9\u30ad\u30e3\u30f3\u304c\u5fc5\u8981\u306a\u3068\u3053\u308d\u306f\u90fd\u5ea6\u5bfe\u5fdc\u3059\u308b\u4e8b\u304c\u51fa\u6765\u307e\u3059\u3002<br \/>\n\u3068\u306f\u3044\u3048\u3001\u304b\u306a\u308a\u5f37\u5f15\u304b\u306a\u3068\u601d\u3048\u308b\u65b9\u6cd5\u306a\u306e\u3067\u3001\u4eca\u5f8c\u898b\u3066\u884c\u304b\u306a\u3044\u3068\u3053\u308c\u3067OK\u304b\u306f\u5206\u304b\u308a\u307e\u305b\u3093\u304c\u30fb\u30fb\u30fb\u3002<br \/>\n\u305d\u308c\u3068\u3001\u3069\u3061\u3089\u3082\u8a31\u5bb9\u7bc4\u56f2\u3067\u306f\u6709\u308a\u307e\u3059\u304c\u3001\u30e1\u30e2\u30ea\u4e0a\u306b\u4e00\u5ea6\u4e57\u308b\u3068\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u4f7f\u308f\u306a\u3044\u691c\u7d22\u306e\u65b9\u304c\u65e9\u3044\u4e8b\u3082\u6709\u308a\u307e\u3059\u3002<\/p>\n<p>\u4f55\u304b\u4ed6\u306b\u826f\u3044\u65b9\u6cd5\u306f\u7121\u3044\u3082\u306e\u304b\u3002<\/p>\n<a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-facebook nolightbox\" data-provider=\"facebook\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Facebook\" href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F1148&#038;t=%E6%AD%A3%E8%A6%8F%E5%8C%96%E3%81%97%E3%81%AA%E3%81%84%E3%81%A8%E9%A7%84%E7%9B%AE%E3%81%8B%E3%81%AA&#038;s=100&#038;p&#091;url&#093;=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F1148&#038;p&#091;images&#093;&#091;0&#093;=&#038;p&#091;title&#093;=%E6%AD%A3%E8%A6%8F%E5%8C%96%E3%81%97%E3%81%AA%E3%81%84%E3%81%A8%E9%A7%84%E7%9B%AE%E3%81%8B%E3%81%AA\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"Facebook\" title=\"Share on Facebook\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/facebook.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-twitter nolightbox\" data-provider=\"twitter\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Twitter\" href=\"http:\/\/twitter.com\/share?url=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F1148&#038;text=%E6%AD%A3%E8%A6%8F%E5%8C%96%E3%81%97%E3%81%AA%E3%81%84%E3%81%A8%E9%A7%84%E7%9B%AE%E3%81%8B%E3%81%AA\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"twitter\" title=\"Share on Twitter\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/twitter.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-linkedin nolightbox\" data-provider=\"linkedin\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Linkedin\" href=\"https:\/\/www.linkedin.com\/shareArticle?mini=true&#038;url=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F1148&#038;title=%E6%AD%A3%E8%A6%8F%E5%8C%96%E3%81%97%E3%81%AA%E3%81%84%E3%81%A8%E9%A7%84%E7%9B%AE%E3%81%8B%E3%81%AA\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"linkedin\" title=\"Share on Linkedin\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/linkedin.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-tumblr nolightbox\" data-provider=\"tumblr\" target=\"_blank\" rel=\"nofollow\" title=\"Share on tumblr\" href=\"https:\/\/tumblr.com\/share?s=&#038;v=3&#038;t=%E6%AD%A3%E8%A6%8F%E5%8C%96%E3%81%97%E3%81%AA%E3%81%84%E3%81%A8%E9%A7%84%E7%9B%AE%E3%81%8B%E3%81%AA&#038;u=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F1148\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"tumblr\" title=\"Share on tumblr\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/tumblr.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-mail nolightbox\" data-provider=\"mail\" rel=\"nofollow\" title=\"Share by email\" href=\"mailto:?subject=%E6%AD%A3%E8%A6%8F%E5%8C%96%E3%81%97%E3%81%AA%E3%81%84%E3%81%A8%E9%A7%84%E7%9B%AE%E3%81%8B%E3%81%AA&#038;body=%E3%82%B7%E3%82%A7%E3%82%A2%E3%81%99%E3%82%8B%EF%BC%9A:%20https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F1148\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"mail\" title=\"Share by email\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/mail.png\" \/><\/a>","protected":false},"excerpt":{"rendered":"<p>PostgreSQL8.1\u3092\u4f7f\u3063\u305f\u3042\u308b\u30b7\u30b9\u30c6\u30e0\u3067\u306e\u304a\u8a71\u3057\u3067\u3059\u3002 \u307e\u305a\u30e6\u30fc\u30b6\u30c7\u30fc\u30bf\u306e\u30c6\u30fc\u30d6\u30eb\u304c\u6709\u308a\u3001\u305d\u306e\u30e6\u30fc\u30b6\u306fID\uff08\u9023\u756a\uff09\u3067\u7ba1\u7406\u3055\u308c\u3066\u3044\u307e\u3059\u3002 \u305d\u3057\u3066\u30e6\u30fc\u30b6\u304c\u767b\u9332\u3059\u308b\u30c7\u30fc\u30bf\u30c6\u30fc\u30d6\u30eb\u306b\u306f\u3001\u30c7\u30fc\u30bf\u3054\u3068\u306b\u305d\u306e\u30c7\u30fc\u30bf\u3092\u5171\u6709\u3059\u308b\u30e6 [&hellip;]<\/p>\n","protected":false},"author":17,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[135],"class_list":["post-1148","post","type-post","status-publish","format-standard","hentry","category-postgresql","tag-postgresql"],"_links":{"self":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts\/1148","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/comments?post=1148"}],"version-history":[{"count":6,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts\/1148\/revisions"}],"predecessor-version":[{"id":8269,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts\/1148\/revisions\/8269"}],"wp:attachment":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/media?parent=1148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/categories?post=1148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/tags?post=1148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}