{"id":20766,"date":"2024-01-02T05:35:25","date_gmt":"2024-01-02T05:35:25","guid":{"rendered":"https:\/\/server.hk\/blog\/20766\/"},"modified":"2024-11-14T10:39:05","modified_gmt":"2024-11-14T02:39:05","slug":"postgresql-command-create-operator-class","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/20766\/","title":{"rendered":"PostgreSQL \u6307\u4ee4\uff1aCREATE OPERATOR CLASS"},"content":{"rendered":"<h1 id=\"postgresql-command-create-operator-class-sPOCKFVMlN\">PostgreSQL \u6307\u4ee4\uff1aCREATE OPERATOR CLASS<\/h1>\n<p>PostgreSQL \u662f\u4e00\u500b\u529f\u80fd\u5f37\u5927\u7684\u958b\u6e90\u95dc\u4fc2\u578b\u8cc7\u6599\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u63d0\u4f9b\u4e86\u5ee3\u6cdb\u7684\u529f\u80fd\u548c\u7279\u9ede\u3002\u5176\u4e3b\u8981\u512a\u52e2\u4e4b\u4e00\u662f\u5176\u53ef\u64f4\u5c55\u6027\uff0c\u5141\u8a31\u7528\u6236\u5b9a\u7fa9\u81ea\u8a02\u64cd\u4f5c\u7b26\u548c\u8cc7\u6599\u985e\u578b\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u5c07\u63a2\u8a0e PostgreSQL \u7684 <code>CREATE OPERATOR CLASS<\/code> \u6307\u4ee4\u53ca\u5176\u5728\u8cc7\u6599\u5eab\u7ba1\u7406\u4e2d\u7684\u91cd\u8981\u6027\u3002<\/p>\n<h2 id=\"understanding-operator-classes-sPOCKFVMlN\">\u7406\u89e3\u64cd\u4f5c\u7b26\u985e\u5225<\/h2>\n<p>\u5728 PostgreSQL \u4e2d\uff0c\u64cd\u4f5c\u7b26\u985e\u5225\u662f\u4e00\u7d44\u64cd\u4f5c\u7b26\u548c\u652f\u63f4\u51fd\u6578\uff0c\u5b9a\u7fa9\u4e86\u7279\u5b9a\u8cc7\u6599\u985e\u578b\u5728\u64cd\u4f5c\u7b26\u65b9\u9762\u7684\u884c\u70ba\u3002\u5b83\u70ba\u67e5\u8a62\u898f\u5283\u5668\u63d0\u4f9b\u5fc5\u8981\u7684\u4fe1\u606f\uff0c\u5f9e\u800c\u512a\u5316\u6d89\u53ca\u6307\u5b9a\u8cc7\u6599\u985e\u578b\u7684\u67e5\u8a62\u3002<\/p>\n<p>\u64cd\u4f5c\u7b26\u985e\u5225\u5728\u8655\u7406\u8907\u96dc\u8cc7\u6599\u985e\u578b\u6216\u81ea\u8a02\u73fe\u6709\u64cd\u4f5c\u7b26\u884c\u70ba\u6642\u5c24\u70ba\u6709\u7528\u3002\u5b83\u5011\u5141\u8a31\u60a8\u64f4\u5c55 PostgreSQL \u7684\u529f\u80fd\uff0c\u4e26\u6839\u64da\u5177\u9ad4\u9700\u6c42\u9032\u884c\u8abf\u6574\u3002<\/p>\n<h2 id=\"the-create-operator-class-command-sPOCKFVMlN\">CREATE OPERATOR CLASS \u6307\u4ee4<\/h2>\n<p><code>CREATE OPERATOR CLASS<\/code> \u6307\u4ee4\u7528\u65bc\u5728 PostgreSQL \u4e2d\u5275\u5efa\u65b0\u7684\u64cd\u4f5c\u7b26\u985e\u5225\u3002\u8a72\u6307\u4ee4\u7684\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>CREATE OPERATOR CLASS name\r\n  DEFAULT FOR TYPE data_type USING index_method\r\n  AS operator_family\r\n  [OPERATOR class_operator [SORT family_sort_operator] [PROCEDURE support_function]\r\n    [, ...]]\r\n<\/code><\/pre>\n<p>\u6211\u5011\u4f86\u62c6\u89e3\u9019\u500b\u6307\u4ee4\u7684\u4e0d\u540c\u7d44\u4ef6\uff1a<\/p>\n<ul>\n<li><code>name<\/code>\uff1a\u6307\u5b9a\u64cd\u4f5c\u7b26\u985e\u5225\u7684\u540d\u7a31\u3002<\/li>\n<li><code>DEFAULT FOR TYPE data_type<\/code>\uff1a\u6307\u5b9a\u64cd\u4f5c\u7b26\u985e\u5225\u6240\u91dd\u5c0d\u7684\u8cc7\u6599\u985e\u578b\u3002<\/li>\n<li><code>USING index_method<\/code>\uff1a\u6307\u5b9a\u64cd\u4f5c\u7b26\u985e\u5225\u6240\u4f7f\u7528\u7684\u7d22\u5f15\u65b9\u6cd5\u3002<\/li>\n<li><code>AS operator_family<\/code>\uff1a\u6307\u5b9a\u64cd\u4f5c\u7b26\u985e\u5225\u6240\u5c6c\u7684\u64cd\u4f5c\u7b26\u5bb6\u65cf\u3002<\/li>\n<li><code>OPERATOR class_operator<\/code>\uff1a\u6307\u5b9a\u8981\u5305\u542b\u5728\u64cd\u4f5c\u7b26\u985e\u5225\u4e2d\u7684\u64cd\u4f5c\u7b26\u3002<\/li>\n<li><code>SORT family_sort_operator<\/code>\uff1a\u6307\u5b9a\u64cd\u4f5c\u7b26\u985e\u5225\u8981\u4f7f\u7528\u7684\u6392\u5e8f\u64cd\u4f5c\u7b26\u3002<\/li>\n<li><code>PROCEDURE support_function<\/code>\uff1a\u6307\u5b9a\u64cd\u4f5c\u7b26\u985e\u5225\u8981\u4f7f\u7528\u7684\u652f\u63f4\u51fd\u6578\u3002<\/li>\n<\/ul>\n<p>\u900f\u904e\u4f7f\u7528 <code>CREATE OPERATOR CLASS<\/code> \u6307\u4ee4\uff0c\u60a8\u53ef\u4ee5\u6839\u64da\u5177\u9ad4\u9700\u6c42\u5b9a\u7fa9\u81ea\u8a02\u64cd\u4f5c\u7b26\u985e\u5225\u3002<\/p>\n<h2 id=\"example-sPOCKFVMlN\">\u7bc4\u4f8b<\/h2>\n<p>\u8b93\u6211\u5011\u8003\u616e\u4e00\u500b\u7bc4\u4f8b\uff0c\u6211\u5011\u60f3\u70ba\u4e00\u500b\u540d\u70ba <code>mytype<\/code> \u7684\u65b0\u8cc7\u6599\u985e\u578b\u5275\u5efa\u81ea\u8a02\u64cd\u4f5c\u7b26\u985e\u5225\u3002\u6211\u5011\u60f3\u5b9a\u7fa9\u4e00\u500b\u65b0\u7684\u64cd\u4f5c\u7b26 <code>=~<\/code>\uff0c\u7528\u65bc\u5c0d\u8a72\u8cc7\u6599\u985e\u578b\u57f7\u884c\u6a21\u5f0f\u5339\u914d\u64cd\u4f5c\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u5275\u5efa\u64cd\u4f5c\u7b26\u985e\u5225\u7684\u65b9\u6cd5\uff1a<\/p>\n<pre><code>CREATE OPERATOR CLASS mytype_ops\r\n  DEFAULT FOR TYPE mytype USING btree\r\n  AS operator_family\r\n  OPERATOR 1 =~ (mytype, mytype) \r\n  SORT family_sort_operator\r\n  PROCEDURE support_function\r\n<\/code><\/pre>\n<p>\u5728\u6b64\u7bc4\u4f8b\u4e2d\uff0c\u6211\u5011\u70ba <code>mytype<\/code> \u8cc7\u6599\u985e\u578b\u5275\u5efa\u4e86\u4e00\u500b\u540d\u70ba <code>mytype_ops<\/code> \u7684\u64cd\u4f5c\u7b26\u985e\u5225\u3002\u6211\u5011\u6307\u5b9a\u8a72\u64cd\u4f5c\u7b26\u985e\u5225\u61c9\u4f7f\u7528 <code>btree<\/code> \u7d22\u5f15\u65b9\u6cd5\uff0c\u4e26\u5b9a\u7fa9\u4e86\u64cd\u4f5c\u7b26 <code>=~<\/code>\u3001\u6392\u5e8f\u64cd\u4f5c\u7b26\u4ee5\u53ca\u652f\u63f4\u51fd\u6578\u3002<\/p>\n<h2 id=\"summary-sPOCKFVMlN\">\u7e3d\u7d50<\/h2>\n<p>PostgreSQL \u7684 <code>CREATE OPERATOR CLASS<\/code> \u6307\u4ee4\u5141\u8a31\u60a8\u70ba\u7279\u5b9a\u8cc7\u6599\u985e\u578b\u5b9a\u7fa9\u81ea\u8a02\u64cd\u4f5c\u7b26\u985e\u5225\u3002\u5b83\u63d0\u4f9b\u4e86\u9748\u6d3b\u6027\uff0c\u8b93\u60a8\u80fd\u5920\u64f4\u5c55 PostgreSQL \u7684\u529f\u80fd\u4e26\u512a\u5316\u6d89\u53ca\u81ea\u8a02\u8cc7\u6599\u985e\u578b\u7684\u67e5\u8a62\u3002\u900f\u904e\u4f7f\u7528\u6b64\u6307\u4ee4\uff0c\u60a8\u53ef\u4ee5\u6839\u64da\u5177\u9ad4\u9700\u6c42\u8abf\u6574 PostgreSQL \u4e26\u63d0\u5347\u8cc7\u6599\u5eab\u7684\u6548\u80fd\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6709\u8208\u8da3\u4e86\u89e3\u66f4\u591a\u6709\u95dc VPS \u4e3b\u6a5f\u89e3\u6c7a\u65b9\u6848\u7684\u8cc7\u8a0a\uff0c\u53ef\u4ee5\u8003\u616e\u67e5\u770b <a href=\"https:\/\/server.hk\">Server.HK<\/a>\u3002\u4ed6\u5011\u63d0\u4f9b\u53ef\u9760\u4e14\u9ad8\u6548\u80fd\u7684 VPS \u4e3b\u6a5f\u670d\u52d9\uff0c\u80fd\u5920\u6eff\u8db3\u60a8\u7684\u696d\u52d9\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PostgreSQL \u6307\u4ee4\uff1aCR&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-20766","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/20766","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=20766"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/20766\/revisions"}],"predecessor-version":[{"id":24345,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/20766\/revisions\/24345"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=20766"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=20766"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=20766"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}