{"id":190470,"date":"2024-11-12T12:51:19","date_gmt":"2024-11-12T04:51:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/190470\/"},"modified":"2024-11-12T12:51:21","modified_gmt":"2024-11-12T04:51:21","slug":"%e7%82%ba%e4%bb%80%e9%ba%bc%e6%88%91%e6%9b%b4%e5%96%9c%e6%ad%a1postgresql%e8%80%8c%e4%b8%8d%e6%98%afmariadb-mysql","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/190470\/","title":{"rendered":"\u70ba\u4ec0\u9ebc\u6211\u66f4\u559c\u6b61PostgreSQL\u800c\u4e0d\u662fMariaDB\/MySQL"},"content":{"rendered":"<h1 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e6%88%91%e6%9b%b4%e5%96%9c%e6%ad%a1postgresql%e8%80%8c%e4%b8%8d%e6%98%afmariadb-mysql-RYEIdnyVrI\">\u70ba\u4ec0\u9ebc\u6211\u66f4\u559c\u6b61PostgreSQL\u800c\u4e0d\u662fMariaDB\/MySQL<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\u4e2d\uff0cPostgreSQL\u548cMariaDB\/MySQL\u662f\u6700\u53d7\u6b61\u8fce\u7684\u9078\u64c7\u4e4b\u4e00\u3002\u96d6\u7136\u9019\u5169\u8005\u90fd\u80fd\u5920\u6709\u6548\u5730\u8655\u7406\u6578\u64da\uff0c\u4f46\u5728\u67d0\u4e9b\u65b9\u9762\uff0cPostgreSQL\u5c55\u73fe\u51fa\u66f4\u5f37\u5927\u7684\u529f\u80fd\u548c\u9748\u6d3b\u6027\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u70ba\u4ec0\u9ebc\u6211\u66f4\u559c\u6b61PostgreSQL\u800c\u4e0d\u662fMariaDB\/MySQL\u3002<\/p>\n<h2 id=\"1-%e6%95%b8%e6%93%9a%e5%ae%8c%e6%95%b4%e6%80%a7%e5%92%8c%e4%ba%8b%e5%8b%99%e6%94%af%e6%8c%81-RYEIdnyVrI\">1. \u6578\u64da\u5b8c\u6574\u6027\u548c\u4e8b\u52d9\u652f\u6301<\/h2>\n<p>PostgreSQL\u4ee5\u5176\u5f37\u5927\u7684\u6578\u64da\u5b8c\u6574\u6027\u548c\u4e8b\u52d9\u652f\u6301\u800c\u805e\u540d\u3002\u5b83\u9075\u5faaACID\uff08\u539f\u5b50\u6027\u3001\u4e00\u81f4\u6027\u3001\u9694\u96e2\u6027\u3001\u6301\u4e45\u6027\uff09\u539f\u5247\uff0c\u9019\u610f\u5473\u8457\u5728\u8655\u7406\u4e8b\u52d9\u6642\uff0c\u6578\u64da\u7684\u5b8c\u6574\u6027\u5f97\u5230\u4e86\u4fdd\u969c\u3002\u76f8\u8f03\u4e4b\u4e0b\uff0c\u96d6\u7136MariaDB\/MySQL\u4e5f\u652f\u6301ACID\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0c\u7279\u5225\u662f\u5728\u4f7f\u7528MyISAM\u5b58\u5132\u5f15\u64ce\u6642\uff0c\u6578\u64da\u7684\u5b8c\u6574\u6027\u53ef\u80fd\u6703\u53d7\u5230\u5f71\u97ff\u3002<\/p>\n<h2 id=\"2-%e6%93%b4%e5%b1%95%e6%80%a7%e5%92%8c%e9%9d%88%e6%b4%bb%e6%80%a7-RYEIdnyVrI\">2. \u64f4\u5c55\u6027\u548c\u9748\u6d3b\u6027<\/h2>\n<p>PostgreSQL\u7684\u64f4\u5c55\u6027\u4f7f\u5176\u6210\u70ba\u4e00\u500b\u975e\u5e38\u9748\u6d3b\u7684\u9078\u64c7\u3002\u7528\u6236\u53ef\u4ee5\u5275\u5efa\u81ea\u5b9a\u7fa9\u6578\u64da\u985e\u578b\u3001\u51fd\u6578\u548c\u64cd\u4f5c\u7b26\uff0c\u9019\u4f7f\u5f97PostgreSQL\u80fd\u5920\u9069\u61c9\u5404\u7a2e\u4e0d\u540c\u7684\u61c9\u7528\u9700\u6c42\u3002\u4f8b\u5982\uff0c\u4f7f\u7528\u8005\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0bSQL\u8a9e\u53e5\u5275\u5efa\u4e00\u500b\u81ea\u5b9a\u7fa9\u6578\u64da\u985e\u578b\uff1a<\/p>\n<pre><code>CREATE TYPE my_custom_type AS (\n    field1 INTEGER,\n    field2 TEXT\n);<\/code><\/pre>\n<p>\u9019\u7a2e\u9748\u6d3b\u6027\u5728MariaDB\/MySQL\u4e2d\u662f\u96e3\u4ee5\u5be6\u73fe\u7684\uff0c\u56e0\u70ba\u5b83\u5011\u7684\u64f4\u5c55\u6027\u76f8\u5c0d\u6709\u9650\u3002<\/p>\n<h2 id=\"3-%e6%94%af%e6%8c%81%e5%9c%b0%e7%90%86%e7%a9%ba%e9%96%93%e6%95%b8%e6%93%9a-RYEIdnyVrI\">3. \u652f\u6301\u5730\u7406\u7a7a\u9593\u6578\u64da<\/h2>\n<p>PostgreSQL\u7684PostGIS\u64f4\u5c55\u4f7f\u5176\u5728\u8655\u7406\u5730\u7406\u7a7a\u9593\u6578\u64da\u65b9\u9762\u8868\u73fe\u51fa\u8272\u3002\u9019\u5c0d\u65bc\u9700\u8981\u5730\u7406\u4fe1\u606f\u7cfb\u7d71\uff08GIS\uff09\u529f\u80fd\u7684\u61c9\u7528\u4f86\u8aaa\uff0cPostgreSQL\u7121\u7591\u662f\u66f4\u597d\u7684\u9078\u64c7\u3002\u8209\u4f8b\u4f86\u8aaa\uff0c\u4f7f\u7528PostGIS\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u8f15\u9b06\u5730\u9032\u884c\u5730\u7406\u67e5\u8a62\uff1a<\/p>\n<pre><code>SELECT name FROM locations\nWHERE ST_DWithin(geom, ST_MakePoint(-73.9857, 40.7484), 1000);<\/code><\/pre>\n<p>\u9019\u6a23\u7684\u67e5\u8a62\u5728MariaDB\/MySQL\u4e2d\u5247\u9700\u8981\u66f4\u591a\u7684\u5de5\u4f5c\u4f86\u5be6\u73fe\u3002<\/p>\n<h2 id=\"4-%e6%9b%b4%e5%bc%b7%e5%a4%a7%e7%9a%84%e6%9f%a5%e8%a9%a2%e5%8a%9f%e8%83%bd-RYEIdnyVrI\">4. \u66f4\u5f37\u5927\u7684\u67e5\u8a62\u529f\u80fd<\/h2>\n<p>PostgreSQL\u63d0\u4f9b\u4e86\u66f4\u5f37\u5927\u7684\u67e5\u8a62\u529f\u80fd\uff0c\u5305\u62ec\u7a97\u53e3\u51fd\u6578\u3001\u516c\u5171\u8868\u8868\u9054\u5f0f\uff08CTE\uff09\u548c\u66f4\u8907\u96dc\u7684JOIN\u64cd\u4f5c\u3002\u9019\u4e9b\u529f\u80fd\u4f7f\u5f97\u958b\u767c\u8005\u80fd\u5920\u7de8\u5beb\u66f4\u9ad8\u6548\u548c\u53ef\u8b80\u7684\u67e5\u8a62\u3002\u4f8b\u5982\uff0c\u4f7f\u7528\u7a97\u53e3\u51fd\u6578\u53ef\u4ee5\u8f15\u9b06\u5730\u8a08\u7b97\u7d2f\u7a4d\u7e3d\u548c\uff1a<\/p>\n<pre><code>SELECT id, amount,\n       SUM(amount) OVER (ORDER BY id) AS running_total\nFROM transactions;<\/code><\/pre>\n<p>\u9019\u5728MariaDB\/MySQL\u4e2d\u53ef\u80fd\u9700\u8981\u66f4\u8907\u96dc\u7684\u67e5\u8a62\u4f86\u5be6\u73fe\u3002<\/p>\n<h2 id=\"5-%e7%a4%be%e5%8d%80%e6%94%af%e6%8c%81%e5%92%8c%e6%96%87%e6%aa%94-RYEIdnyVrI\">5. \u793e\u5340\u652f\u6301\u548c\u6587\u6a94<\/h2>\n<p>PostgreSQL\u64c1\u6709\u4e00\u500b\u6d3b\u8e8d\u7684\u958b\u6e90\u793e\u5340\uff0c\u63d0\u4f9b\u4e86\u8c50\u5bcc\u7684\u6587\u6a94\u548c\u8cc7\u6e90\u3002\u9019\u4f7f\u5f97\u958b\u767c\u8005\u5728\u9047\u5230\u554f\u984c\u6642\u80fd\u5920\u66f4\u5bb9\u6613\u5730\u627e\u5230\u89e3\u6c7a\u65b9\u6848\u3002\u76f8\u5c0d\u800c\u8a00\uff0cMariaDB\/MySQL\u7684\u793e\u5340\u652f\u6301\u96d6\u7136\u4e5f\u4e0d\u932f\uff0c\u4f46\u5728\u67d0\u4e9b\u7279\u5b9a\u554f\u984c\u4e0a\uff0cPostgreSQL\u7684\u8cc7\u6e90\u66f4\u70ba\u8c50\u5bcc\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-RYEIdnyVrI\">\u7e3d\u7d50<\/h2>\n<p>\u7e3d\u7684\u4f86\u8aaa\uff0cPostgreSQL\u5728\u6578\u64da\u5b8c\u6574\u6027\u3001\u64f4\u5c55\u6027\u3001\u5730\u7406\u7a7a\u9593\u6578\u64da\u652f\u6301\u3001\u67e5\u8a62\u529f\u80fd\u4ee5\u53ca\u793e\u5340\u652f\u6301\u7b49\u65b9\u9762\u90fd\u5c55\u73fe\u51fa\u512a\u65bcMariaDB\/MySQL\u7684\u7279\u9ede\u3002\u9019\u4e9b\u512a\u52e2\u4f7f\u5f97PostgreSQL\u6210\u70ba\u8a31\u591a\u958b\u767c\u8005\u548c\u4f01\u696d\u7684\u9996\u9078\u6578\u64da\u5eab\u7cfb\u7d71\u3002\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u80fd\u7684\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\uff0c\u8003\u616e\u4f7f\u7528PostgreSQL\u53ef\u80fd\u6703\u662f\u660e\u667a\u7684\u9078\u64c7\u3002\u82e5\u60a8\u9700\u8981\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u4f86\u904b\u884c\u60a8\u7684\u6578\u64da\u5eab\uff0cServer.HK\u63d0\u4f9b\u4e86\u591a\u7a2e\u9078\u64c7\uff0c\u9069\u5408\u5404\u7a2e\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u70ba\u4ec0\u9ebc\u6211\u66f4\u559c\u6b61PostgreSQL\uff0c\u5f9e\u5176\u5f37\u5927\u7684\u529f\u80fd\u3001\u9748\u6d3b\u6027\u5230\u512a\u8d8a\u7684\u6027\u80fd\uff0c\u8b93\u6578\u64da\u7ba1\u7406\u66f4\u9ad8\u6548\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-190470","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/190470","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"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=190470"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/190470\/revisions"}],"predecessor-version":[{"id":190471,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/190470\/revisions\/190471"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=190470"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=190470"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=190470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}