{"id":10006311,"date":"2022-08-25T09:59:02","date_gmt":"2022-08-25T01:59:02","guid":{"rendered":"https:\/\/ityet.com\/?p=10006311"},"modified":"2022-08-25T09:59:02","modified_gmt":"2022-08-25T01:59:02","slug":"%e5%be%ae%e4%bf%a1%e4%b8%ba%e4%bb%80%e4%b9%88%e4%bd%bf%e7%94%a8-sqlite-%e4%bf%9d%e5%ad%98%e8%81%8a%e5%a4%a9%e8%ae%b0%e5%bd%95%ef%bc%9f%ef%bc%88%e6%9d%a5%e9%95%bf%e9%95%bf%e8%a7%81%e8%af%86%e4%ba%86","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10006311","title":{"rendered":"\u5fae\u4fe1\u4e3a\u4ec0\u4e48\u4f7f\u7528 SQLite \u4fdd\u5b58\u804a\u5929\u8bb0\u5f55\uff1f\uff08\u6765\u957f\u957f\u89c1\u8bc6\u4e86\uff01\uff09"},"content":{"rendered":"<blockquote><p>SQLite \u662f\u4e00\u4e2a\u88ab\u5927\u5bb6\u4f4e\u4f30\u7684\u6570\u636e\u5e93\uff0c\u4f46\u6709\u4e9b\u4eba\u8ba4\u4e3a\u5b83\u662f\u4e00\u4e2a\u4e0d\u9002\u5408\u751f\u4ea7\u73af\u5883\u4f7f\u7528\u7684\u73a9\u5177\u6570\u636e\u5e93\u3002\u4e8b\u5b9e\u4e0a\uff0cSQLite \u662f\u4e00\u4e2a\u975e\u5e38\u53ef\u9760\u7684\u6570\u636e\u5e93\uff0c\u5b83\u53ef\u4ee5\u5904\u7406 TB \u7ea7\u7684\u6570\u636e\uff0c\u4f46\u5b83\u6ca1\u6709\u7f51\u7edc\u5c42\u3002\u63a5\u4e0b\u6765\uff0c\u672c\u6587\u5c06\u4e0e\u5927\u5bb6\u5171\u540c\u63a2\u8ba8 SQLite \u5728\u8fc7\u53bb\u4e00\u5e74\u4e2d\u6700\u65b0\u7684 SQL \u529f\u80fd\u3002<\/p><\/blockquote>\n<p>SQLite \u201c\u53ea\u662f\u201d\u4e00\u4e2a\u5e93\uff0c\u5b83\u4e0d\u662f\u4f20\u7edf\u610f\u4e49\u4e0a\u7684\u670d\u52a1\u5668\u3002\u56e0\u6b64\uff0c\u5728\u67d0\u4e9b\u573a\u5408\u4e0b\uff0c\u5b83\u786e\u5b9e\u4e0d\u5408\u9002\u3002\u4f46\u662f\uff0c\u5728\u76f8\u5f53\u591a\u7684\u5176\u4ed6\u573a\u5408\uff0c\u5b83\u5374\u662f\u6700\u5408\u9002\u7684\u9009\u62e9\u3002SQLite \u53f7\u79f0\u662f\u90e8\u7f72\u548c\u4f7f\u7528\u6700\u5e7f\u6cdb\u7684\u6570\u636e\u5e93\u5f15\u64ce\u3002\u6211\u8ba4\u4e3a\u8fd9\u5f88\u6709\u53ef\u80fd\uff0c\u56e0\u4e3a SQLite \u6ca1\u6709\u7248\u6743\u7684\u9650\u5236\u3002\u65e0\u8bba\u4f55\u65f6\uff0c\u53ea\u8981\u5f00\u53d1\u8005\u60f3\u4f7f\u7528 SQL \u5728\u6587\u4ef6\u4e2d\u5b58\u50a8\u7ed3\u6784\u5316\u7684\u6570\u636e\uff0cSQLite \u5e94\u662f\u9996\u9009\u65b9\u6848\u3002<\/p>\n<p>SQLite \u7684 SQL \u65b9\u8a00\u4e5f\u975e\u5e38\u5f3a\u5927\u3002\u5b83\u6bd4 MySQL \u65e9\u56db\u5e74\u5c31\u5f00\u59cb\u652f\u6301 with \u8bed\u53e5\u3002\u6700\u8fd1\uff0c\u5b83\u8fd8\u5b9e\u73b0\u4e86\u5bf9\u4e8e\u7a97\u53e3\u51fd\u6570\u7684\u652f\u6301\uff0c\u8fd9\u4ec5\u4ec5\u6bd4 MySQL \u665a\u4e94\u4e2a\u6708\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u672c\u6587\u5c06\u4ecb\u7ecd SQLite \u5728 2018 \u5e74\u65b0\u589e\u52a0\u7684 SQL \u529f\u80fd\uff0c\u4e5f\u5c31\u662f SQLite \u4ece\u7248\u672c 3.22.0 \u5230 3.26.0 \u6240\u65b0\u589e\u52a0\u7684 SQL \u529f\u80fd\u3002<\/p>\n<p>\u5177\u4f53\u5185\u5bb9\u5305\u62ec\uff1a<\/p>\n<ol>\n<li>\u5e03\u5c14\u5b57\u9762\u91cf\u548c\u5224\u65ad<\/li>\n<li>\u7a97\u53e3\u51fd\u6570<\/li>\n<li>Filter\u5b50\u53e5<\/li>\n<li>Insert \u2026 on conflict (\u201cUpsert\u201d)<\/li>\n<li>\u91cd\u547d\u540d\u5217<\/li>\n<li>\u5728Modern-SQL.com\u4e0a\u63a5\u4e0b\u6765<\/li>\n<\/ol>\n<p><strong>\u5e03\u5c14\u53d8\u91cf\u548c\u5224\u65ad<\/strong><\/p>\n<p>SQLite\u652f\u6301\u201c\u5047\u201d\u5e03\u5c14\u503c\uff1a\u5b83\u63a5\u53d7Boolean\u4f5c\u4e3a\u7c7b\u578b\u7684\u540d\u79f0\uff0c\u4f46\u5b83\u5c06\u5176\u5f53\u4f5c\u6574\u6570\u770b\u5f85\uff08\u8fd9\u4e00\u70b9\u975e\u5e38\u7c7b\u4f3c\u4e8eMySQL\uff09\u3002\u771f\u503ctrue\u548cfalse\u5206\u522b\u7531\u6570\u503c1\u548c0\u8868\u793a\uff08\u8fd9\u4e00\u70b9\u548cC\u8bed\u8a00\u4e00\u6837\uff09\u3002<\/p>\n<p>\u4ece\u7248\u672c3.23.0\u5f00\u59cb\uff0cSQLite\u5c06\u5173\u952e\u5b57true\u548cfalse\u5206\u522b\u7528\u6570\u5b571\u548c0\u8868\u793a\uff0c\u5e76\u652f\u6301is [not] true | false\u7684\u5224\u65ad\u8bed\u53e5\u3002\u73b0\u5728\uff0c\u5b83\u4e0d\u518d\u652f\u6301\u5173\u952e\u5b57unknown\u3002\u5f00\u53d1\u8005\u53ef\u4ee5\u4f7f\u7528\u7a7a\u503cnull\u6765\u4ee3\u66ff\uff0c\u56e0\u4e3aunknown\u548cnull\u7684\u5e03\u5c14\u503c\u662f\u4e00\u6837\u7684\u3002<\/p>\n<p>\u5728INSERT\u548cUPDATE\u8bed\u53e5\u4e2d\uff0c\u5b57\u9762\u91cftrue\u548cfalse\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8values\u548cset\u5b50\u53e5\u7684\u53ef\u8bfb\u6027\u3002<\/p>\n<p>is [not] true | false\u8fd9\u4e2a\u5224\u65ad\u8bed\u53e5\u5f88\u6709\u7528\uff0c\u5b83\u4e0e\u6bd4\u8f83\u64cd\u4f5c\u7684\u542b\u4e49\u4e0d\u4e00\u6837\uff1a<\/p>\n<p>\u6211\u4eec\u6765\u6bd4\u8f83\u4e00\u4e0b<\/p>\n<pre><code>WHERE c &lt;&gt; FALSE<\/code><\/pre>\n<p>\u548c<\/p>\n<pre><code>WHERE c IS NOT FALSE<\/code><\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u5982\u679cc\u662fnull, \u90a3\u4e48c &lt;&gt; false\u7684\u7ed3\u679c\u662funknown.<\/p>\n<p>\u8fd9\u662f\u56e0\u4e3aWHERE\u5b50\u53e5\u53ea\u63a5\u53d7\u7ed3\u679c\u4e3atrue\u7684\u503c\uff0c\u5b83\u4f1a\u8fc7\u6ee4\u6389\u7ed3\u679c\u4e3afalse\u6216unknown\u7684\u503c\u3002\u8fd9\u6837\uff0c\u5b83\u5c31\u4f1a\u628a\u5bf9\u5e94\u7684\u884c\u4ece\u7ed3\u679c\u4e2d\u53bb\u6389\u3002<\/p>\n<p>\u4e0e\u6b64\u76f8\u5bf9\u5e94\uff0c\u5982\u679cc\u662fnull\uff0c\u90a3\u4e48\uff0cc is not false\u7684\u5224\u65ad\u7ed3\u679c\u662ftrue\u3002\u56e0\u6b64\uff0c\u7b2c\u4e8c\u4e2aWHERE\u5b50\u53e5\u4e5f\u5c06\u5305\u542bc\u662fnull\u7684\u884c\u3002<\/p>\n<p>\u8981\u8fbe\u5230\u540c\u6837\u7684\u6548\u679c\uff0c\u60a8\u53ef\u4ee5\u91c7\u7528\u7684\u53e6\u5916\u4e00\u79cd\u65b9\u6cd5\u662f\u589e\u52a0\u5355\u72ec\u5904\u7406null\u503c\u7684\u5b50\u53e5\u3002\u4e5f\u5c31\u662f\u4f7f\u7528\u8bed\u53e5:<\/p>\n<pre><code>WHERE c &lt;&gt; FALSE\n   OR c IS NULL<\/code><\/pre>\n<p>\u8fd9\u79cd\u5f62\u5f0f\u7684\u8bed\u53e5\u66f4\u957f\u5e76\u4e14\u6709\u4e00\u4e9b\u5197\u4f59\u8bed\u53e5\uff08c\u88ab\u4f7f\u7528\u4e86\u4e24\u6b21\uff09\u3002\u957f\u8bdd\u77ed\u8bf4\uff0c\u53ef\u4ee5\u4f7f\u7528is not false\u5224\u65ad\u6765\u66ff\u4ee3\u8fd9\u4e2aor\u2026is-null\u7684\u8bed\u53e5\u3002\u66f4\u8be6\u7ec6\u7684\u5185\u5bb9\uff0c\u8bf7\u53c2\u8003\u201cBinary Decisions Based on Three-Valued Results\u201d\u3002<\/p>\n<p>SQLite\u4e2d\u5bf9\u5e03\u5c14\u5b57\u9762\u91cf\u548c\u5e03\u5c14\u5224\u65ad\u7684\u652f\u6301\u73b0\u5728\u548c\u5176\u4ed6\u5f00\u6e90\u6570\u636e\u5e93\u63a5\u8fd1\uff0c\u552f\u4e00\u7684\u5dee\u8ddd\u662fSQLite\u4e0d\u652f\u6301is[not] unknown\uff08\u4f60\u53ef\u4ee5\u4f7f\u7528is [not] null\u6765\u4ee3\u66ff\uff09\u3002\u6709\u8da3\u7684\u662f\uff0c\u8fd9\u4e9b\u529f\u80fd\u5728\u4e0b\u9762\u63d0\u5230\u7684\u5546\u7528\u4ea7\u54c1\u4e2d\u8fd8\u4e0d\u53ef\u7528\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042373123\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>0\uff1a\u53ea\u652f\u6301true,false.\u4e0d\u652f\u6301notknown\uff0c\u5982\u679c\u9700\u8981\uff0c\u7528null\u4ee3\u66ff<\/p>\n<p>1\uff1a\u4e0d\u652f\u6301is [not] unknown,\u5982\u679c\u9700\u8981\uff0c\u7528is [not] null\u4ee3\u66ff<\/p>\n<p><strong>\u7a97\u53e3\u51fd\u6570<\/strong><\/p>\n<p>SQLite 3.25.0\u5f15\u5165\u4e86\u7a97\u53e3\u51fd\u6570\u3002\u5982\u679c\u4f60\u77e5\u9053\u7a97\u53e3\u51fd\u6570\uff0c\u90a3\u4e48\u4e5f\u77e5\u9053\u8fd9\u662f\u4e00\u4ef6\u5927\u4e8b\u3002\u5982\u679c\u4f60\u4e0d\u4e86\u89e3\u7a97\u53e3\u529f\u80fd\uff0c\u8bf7\u4f60\u81ea\u5df1\u5b66\u4e60\u5982\u4f55\u4f7f\u7528\u3002\u8fd9\u7bc7\u6587\u7ae0\u4e0d\u4f1a\u5177\u4f53\u89e3\u91ca\u7a97\u53e3\u51fd\u6570\uff0c\u4f46\u8bf7\u76f8\u4fe1\uff1a\u5b83\u662f\u6700\u91cd\u8981\u7684\u201c\u73b0\u4ee3\u201dSQL\u7279\u6027\u3002<\/p>\n<p>SQLite\u5bf9over\u5b50\u53e5\u7684\u652f\u6301\u4e0e\u5176\u4ed6\u6570\u636e\u5e93\u975e\u5e38\u63a5\u8fd1\u3002\u552f\u4e00\u503c\u5f97\u6ce8\u610f\u7684\u9650\u5236\u662frange\u8bed\u53e5\u4e0d\u652f\u6301\u6570\u5b57\u6216\u95f4\u9694\u8ddd\u79bb\uff08\u4ec5\u652f\u6301current row\u548cunbounded preceding|following\uff09\u3002\u5728\u53d1\u5e03sqlite 3.25.0\u65f6,SQL Server\u548cPostgreSQL\u5177\u6709\u540c\u6837\u7684\u9650\u5236\u3002PostgreSQL 11\u6d88\u9664\u4e86\u8fd9\u4e00\u9650\u5236\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042373124\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>0\uff1a\u6ca1\u6709\u53d8\u5316<\/p>\n<p>1\uff1aRange\u8303\u56f4\u5b9a\u4e49\u4e0d\u652f\u6301datetime\u7c7b\u578b<\/p>\n<p>2\uff1aRange\u8303\u56f4\u4e0d\u63a5\u53d7\u5173\u952e\u5b57 (\u53ea\u652f\u6301unbounded\u548ccurrent row)<\/p>\n<p>SQLite\u5bf9\u4e8e\u7a97\u53e3\u51fd\u6570\u7684\u652f\u6301\u5728\u4e1a\u754c\u662f\u9886\u5148\u7684\u3002\u5b83\u4e0d\u652f\u6301\u7684\u529f\u80fd\u5728\u5176\u4ed6\u4e00\u4e9b\u4e3b\u8981\u4ea7\u54c1\u4e2d\u4e5f\u540c\u6837\u4e0d\u652f\u6301\uff08\u5728\u805a\u5408\u4e2d\u8bed\u53e5\u4e2d\u7684distinct\uff0cwidth_bucket\uff0c respect|ignore nulls\u548cfrom first|last\u7b49\u8bed\u53e5\uff09\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042373125\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>0\uff1a\u540c\u6837\u6ca1\u6709ORDER BY \u8bed\u53e5<\/p>\n<p>1\uff1a\u4e0d\u5141\u8bb8\u8d1f\u504f\u79fb\u91cf\uff0cnulls\u7684\u7279\u5b9a\u5904\u7406\uff1alead(, &#8216;IGNORE NULLS&#8217;)\uff0c\u8fd9\u91cc\u662f\u5b57\u7b26\u4e32\u53c2\u6570<\/p>\n<p>2\uff1a\u6ca1\u6709\u7f3a\u7701\u503c(\u7b2c\u4e09\u4e2a\u53c2\u6570)\uff0c\u4e0d\u652f\u6301respect|ignore nulls\u8bed\u53e5<\/p>\n<p>3\uff1a\u4e0d\u5141\u8bb8\u8d1f\u504f\u79fb\u91cf\uff0c\u4e0d\u652f\u6301ignore nulls\u8bed\u53e5<\/p>\n<p>4\uff1a\u4e0d\u5141\u8bb8\u8d1f\u504f\u79fb\u91cf<\/p>\n<p>5\uff1a\u4e0d\u652f\u6301respect|ignore nulls\u8bed\u53e5<\/p>\n<p>6\uff1a\u4e0d\u5141\u8bb8\u8d1f\u504f\u79fb\u91cf\uff0c\u4e0d\u652f\u6301respect|ignore nulls\u8bed\u53e5<\/p>\n<p>7\uff1anulls\u7684\u7279\u5b9a\u5904\u7406\uff1afirst_value(, 1, null, &#8216;IGNORE NULLS&#8217;) \uff0c\u8fd9\u91cc\u662f\u5b57\u7b26\u4e32\u53c2\u6570\u3002<\/p>\n<p>8\uff1a\u4e0d\u652f\u6301ignore nulls\u8bed\u53e5<\/p>\n<p>9\uff1a\u4e0d\u652f\u6301ignore nulls\u8bed\u53e5\u548cfrom last\u8bed\u53e5<\/p>\n<p><strong>\u8fc7\u6ee4\u8bed\u53e5<\/strong><\/p>\n<p>\u867d\u7136filter\u8bed\u53e5\u53ea\u662f\u8bed\u6cd5\u7cd6\u2014\u2014\u4f60\u4e5f\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u4f7f\u7528\u8868\u8fbe\u5f0f\u6765\u83b7\u5f97\u76f8\u540c\u7684\u7ed3\u679c\u2014\u2014\u6211\u8ba4\u4e3a\u5b83\u4e5f\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u8bed\u6cd5\u7cd6\uff0c\u56e0\u4e3a\u5b83\u80fd\u4f7f\u4eba\u4eec\u66f4\u52a0\u5bb9\u6613\u5730\u5b66\u4e60\u548c\u7406\u89e3SQL\u8bed\u53e5\u3002<\/p>\n<p>\u770b\u770b\u4e0b\u9762\u7684select\u5b50\u53e5\uff0c\u60a8\u89c9\u5f97\u54ea\u4e00\u4e2a\u66f4\u5bb9\u6613\u7406\u89e3\uff1f<\/p>\n<pre><code>SELECT SUM(revenue) total_revenue\n     , SUM(CASE WHEN product = 1\n                THEN revenue\n            END\n          ) prod1_revenue\n   ...<\/code><\/pre>\n<p>\u548c<\/p>\n<pre><code>SELECT SUM(revenue) total_revenue\n     , SUM(revenue) FILTER(WHERE product = 1) prod1_revenue\n   ...<\/code><\/pre>\n<p>\u6b64\u793a\u4f8b\u5f88\u597d\u5730\u603b\u7ed3\u4e86filter\u5b50\u53e5\u7684\u4f5c\u7528\uff1a\u5b83\u662f\u805a\u5408\u51fd\u6570\u7684\u540e\u7f00\uff0c\u53ef\u4ee5\u5728\u8fdb\u884c\u805a\u5408\u4e4b\u524d\u6839\u636e\u7279\u5b9a\u6761\u4ef6\uff0c\u8fc7\u6ee4\u6389\u76f8\u5e94\u7684\u884c\u3002pivot\u6280\u672f\u662ffilter\u5b50\u53e5\u6700\u5e38\u89c1\u7684\u7528\u4f8b\u3002\u8fd9\u5305\u62ec\u5c06\u5b9e\u4f53\u5c5e\u6027\u503c\uff08EAV\uff09\u6a21\u578b\u4e2d\u7684\u5c5e\u6027\u8f6c\u6362\u4e3a\u8868\u683c\u7684\u5217\uff0c\u5982\u679c\u60f3\u4e86\u89e3\u66f4\u591a\u7684\u5185\u5bb9\uff0c\u53ef\u4ee5\u53c2\u8003\u94fe\u63a5\u201cfilter-Selective Aggregates\u201d\uff08<a href=\"https:\/\/link.segmentfault.com\/?enc=vXaSqo8kTDTRuNWdxU7qPw%3D%3D.Rn1v9HfTHBgXC3VcoKDq1N0hohCZVMRw0RvEcLEk6AZRIRykW7vTGYnFNKGxOolv\" rel=\"nofollow\">https:\/\/modern-sql.com\/featur&#8230;<\/a>\uff09\u3002<\/p>\n<p>SQLite \u4ece\u7248\u672c3.25.0\u5f00\u59cb\uff0c\u5728\u4f7f\u7528over\u5b50\u53e5\u7684\u805a\u5408\u51fd\u6570\u4e2d\u652f\u6301\u4e86filter\u5b50\u53e5\uff0c\u4f46\u662f\u5728\u4f7f\u7528group by\u5b50\u53e5\u7684\u805a\u5408\u51fd\u6570\u4e2d\u8fd8\u4e0d\u652f\u6301\u3002\u4e0d\u5e78\u7684\u662f\uff0c\u8fd9\u610f\u5473\u7740\u60a8\u4ecd\u7136\u65e0\u6cd5\u5728SQLite\u4e2d\u4f7f\u7528filter\u8bed\u53e5\u6765\u5904\u7406\u4e0a\u8ff0\u60c5\u51b5\u3002\u4f60\u5fc5\u987b\u50cf\u4ee5\u524d\u4e00\u6837\u4f7f\u7528case\u8868\u8fbe\u5f0f\u3002\u6211\u771f\u7684\u5e0c\u671bSQLite\u5728\u8fd9\u4e00\u70b9\u4e0a\u80fd\u5c3d\u5feb\u505a\u5230\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042373126\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><strong>Insert \u2026 on conflict (\u201cUpsert\u201d)<\/strong><\/p>\n<p>SQLite \u4ece\u7248\u672c3.24.0\u5f00\u59cb\uff0c\u5f15\u5165\u4e86\u201cupsert\u201d\u6982\u5ff5\uff1a\u5b83\u662f\u4e00\u4e2ainsert\u8bed\u53e5\uff0c\u53ef\u4ee5\u4f18\u96c5\u5730\u5904\u7406\u4e3b\u952e\u548c\u552f\u4e00\u7ea6\u675f\u7684\u51b2\u7a81\u3002\u60a8\u53ef\u4ee5\u9009\u62e9\u5ffd\u7565\u8fd9\u4e9b\u51b2\u7a81\uff08\u5728on conflict\u8bed\u53e5\u4e2d\u4ec0\u4e48\u90fd\u4e0d\u505a\uff09\u6216\u8005\u66f4\u65b0\u5f53\u524d\u884c\uff08\u5728on conflict\u8bed\u53e5\u4e2d\u6267\u884c\u66f4\u65b0\u64cd\u4f5c\uff09\u3002<\/p>\n<p>\u8fd9\u662f\u4e00\u4e2a\u7279\u6709\u7684SQL\u6269\u5c55\uff0c\u5373\u5b83\u4e0d\u662f\u6807\u51c6SQL\u7684\u4e00\u90e8\u5206\uff0c\u56e0\u6b64\u5728\u4e0b\u9762\u7684\u77e9\u9635\u4e2d\u662f\u7070\u8272\u7684\u3002\u4f46\u662f\uff0cSQLite\u9075\u5b88\u4e0ePostgreSQL\u76f8\u540c\u7684\u8bed\u6cd5\u6765\u5b9e\u73b0\u6b64\u529f\u80fd0\u3002\u8be5\u6807\u51c6\u63d0\u4f9b\u4e86\u5bf9merge\u8bed\u53e5\u7684\u652f\u6301\u3002<\/p>\n<p>\u4e0ePostgreSQL\u4e0d\u540c\uff0cSQLite\u5728\u4ee5\u4e0b\u8bed\u53e5\u4e2d\u5b58\u5728\u95ee\u9898\u3002<\/p>\n<pre><code>INSERT INTO target\nSELECT *\n  FROM source\n    ON CONFLICT (id)\n    DO UPDATE SET val = excluded.val<\/code><\/pre>\n<p>\u6839\u636e\u8bf4\u660e\u6587\u6863\uff0c\u8fd9\u662f\u56e0\u4e3a\u89e3\u6790\u5668\u65e0\u6cd5\u5224\u65ad\u5173\u952e\u5b57ON\u662fSELECT\u8bed\u53e5\u7684\u8fde\u63a5\u7ea6\u675f\u8fd8\u662fupsert\u5b50\u53e5\u7684\u5f00\u5934\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u5411\u67e5\u8be2\u4e2d\u6dfb\u52a0\u5b50\u53e5\u6765\u89e3\u51b3\uff0c\u4f8b\u5982where true\u3002<\/p>\n<pre><code>INSERT INTO target\nSELECT *\n  FROM source\n WHERE true\n    ON CONFLICT (id)\n    DO UPDATE SET val = excluded.val<\/code><\/pre>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042373127\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>0\uff1a\u540c\u6837\u8bb0\u5f55insert\u3001update\u3001delete\u548cmerge\u64cd\u4f5c\u7684\u9519\u8bef\u4fe1\u606f (\u201cDML error logging\u201d)<\/p>\n<p>1\uff1aOn conflict\u8bed\u53e5\u4e0d\u80fd\u7d27\u6328\u67e5\u8be2\u7684from\u8bed\u53e5\uff0c\u5982\u679c\u9700\u8981\uff0c\u53ef\u4ee5\u6dfb\u52a0  where true\u8bed\u53e5\u6765\u5206\u9694\u3002<\/p>\n<p><strong>\u91cd\u547d\u540d\u5217<\/strong><\/p>\n<p>SQLite\u5f15\u5165\u7684\u53e6\u4e00\u4e2a\u7279\u6709\u529f\u80fd\u662f\u91cd\u547d\u540d\u57fa\u51c6\u6570\u636e\u5e93\u8868\u4e2d\u7684\u52171\u3002\u6807\u51c6\u7684SQL\u4e0d\u652f\u6301\u6b64\u7c7b\u529f\u80fd2\u3002<\/p>\n<p>SQLite\u9075\u5faa\u5176\u4ed6\u4ea7\u54c1\u5e38\u7528\u7684\u8bed\u6cd5\u6765\u91cd\u547d\u540d\u5217\uff1a<\/p>\n<blockquote><p>ALTER TABLE \u2026 RENAME COLUMN \u2026 TO<\/p><\/blockquote>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042373128\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<blockquote><p>0\uff1a\u8bf7\u67e5\u9605 sp_rename.<\/p><\/blockquote>\n<p><strong>\u5176\u4ed6\u6d88\u606f<\/strong><\/p>\n<p>\u57282018\u5e74\uff0cSQLite\u9664\u4e86\u5728SQL\u8bed\u6cd5\u4e0a\u7684\u53d8\u5316\uff0c\u8fd8\u6709\u4e00\u4e9b\u5e94\u7528\u7a0b\u5e8f\u63a5\u53e3\uff08API\uff09\u7684\u53d8\u5316\u3002\u4f60\u53ef\u4ee5\u67e5\u9605sqlite.com\uff08<a href=\"https:\/\/link.segmentfault.com\/?enc=icMuWTxyB4APfNcgRoLdxQ%3D%3D.%2B1xtVk8Y4C%2BGou2BgRjh2SyT1QV%2FfNJeTF5o6KU92Nk%2FRnyUtnhNqv0GmL2PvDhu\" rel=\"nofollow\">https:\/\/www.sqlite.org\/news.html<\/a>\uff09\u4e0a\u7684\u65b0\u95fb\u90e8\u5206\u6765\u4e86\u89e3\u66f4\u8be6\u7ec6\u7684\u6d88\u606f\u3002<\/p>\n<p><strong>\u811a\u6807:<\/strong><\/p>\n<ul>\n<li>0\uff1aSQLite\u901a\u5e38\u9075\u5faaPostgreSQL\u8bed\u6cd5\uff0cRichard Hipp\u5c06\u6b64\u79f0\u4e3aPostgreSQL\u4f1a\u600e\u4e48\u505a\uff08WWPD\uff09\u3002<\/li>\n<li>1\uff1a\u57fa\u51c6\u6570\u636e\u5e93\u8868\u662f\u6307\u7528Create table\u8bed\u53e5\u521b\u5efa\u7684\u6570\u636e\u5e93\u8868\u3002\u6d3e\u751f\u7684\u6570\u636e\u5e93\u8868\uff08\u5982Select\u8bed\u53e5\u8fd4\u56de\u7684\u67e5\u8be2\u7ed3\u679c\u96c6\uff09\u4e2d\u7684\u5217\u540d\u53ef\u4ee5\u901a\u8fc7SELECT\u8bed\u53e5\u3001FROM\u8bed\u53e5\u6216WITH\u8bed\u53e5\u6765\u8fdb\u884c\u6539\u53d8<\/li>\n<li>2\uff1a\u636e\u6211\u6240\u77e5\uff0c\u4e5f\u8bb8\u53ef\u4ee5\u901a\u8fc7\u53ef\u66f4\u65b0\u89c6\u56fe\u6216\u6d3e\u751f\u7684\u5217\u6765\u6a21\u62df\u8be5\u529f\u80fd\u3002<\/li>\n<\/ul>\n<blockquote><p>\u539f\u6587\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=vfzoW1k4ERn5xBMRB3Uq5Q%3D%3D.ZX1ex4QiBJ4FneUM9xCSl8zZpSg3m2ygrqJw8H%2F7sBdbLyCArzODKSkGaCsCwV%2Bv0iQxT2crFGHJQZC7gNtpAA%3D%3D\" rel=\"nofollow\">https:\/\/modern-sql.com\/blog\/2&#8230;<\/a><\/p><\/blockquote>\n<p><strong>\u8fd1\u671f\u70ed\u6587\u63a8\u8350\uff1a<\/strong><\/p>\n<p>1.<a href=\"https:\/\/link.segmentfault.com\/?enc=dzPPnMum4qf4xmG2gcr56A%3D%3D.umivGCfMW3Cx72xCYjdrFfkv74Tp7rE9tlRydEv8GSs%3D\" rel=\"nofollow\">1,000+ \u9053 Java\u9762\u8bd5\u9898\u53ca\u7b54\u6848\u6574\u7406(2022\u6700\u65b0\u7248)<\/a><\/p>\n<p>2.<a href=\"https:\/\/link.segmentfault.com\/?enc=bNw64YG70vJCXUfRvOirGQ%3D%3D.J9da2bg8VSW68YzPr2EeQbWQvUj4Boi3c2Lx1YnQdXackiX2CH3%2FGoJcDFtFJbb9Zmvd9QS4ZZxf4xxteDvaHw%3D%3D\" rel=\"nofollow\">\u52b2\u7206\uff01Java \u534f\u7a0b\u8981\u6765\u4e86\u3002\u3002\u3002<\/a><\/p>\n<p>3.<a href=\"https:\/\/link.segmentfault.com\/?enc=o2lBTNH4aDM4xRTJhjGLmQ%3D%3D.2YTeOAOXojHLiGJKDfhhiErYU5zuzJFfzyP91wkibvtAhXbEUfhI5DBb1GCOcmNn\" rel=\"nofollow\">Spring Boot 2.x \u6559\u7a0b\uff0c\u592a\u5168\u4e86\uff01<\/a><\/p>\n<p>4.<a href=\"https:\/\/link.segmentfault.com\/?enc=vWuYoScTuv3R%2ByXveNwB2A%3D%3D.vZ4ttC%2BYrSGPkjnMJOvBmWFNuqX4Oh8R3d%2F1EvpWFZM76p1KWcupFuF7FfovGvSmb01GTi%2BUdaVGrDDgHNntvw%3D%3D\" rel=\"nofollow\">\u522b\u518d\u5199\u6ee1\u5c4f\u7684\u7206\u7206\u7206\u70b8\u7c7b\u4e86\uff0c\u8bd5\u8bd5\u88c5\u9970\u5668\u6a21\u5f0f\uff0c\u8fd9\u624d\u662f\u4f18\u96c5\u7684\u65b9\u5f0f\uff01\uff01<\/a><\/p>\n<p>5.<a href=\"https:\/\/link.segmentfault.com\/?enc=NaoddwUepxMCfj6leMOymA%3D%3D.zqupA3qoKD%2B%2FVaV1H4%2FS%2FC2BdTQsX0tEfmdy2zcV8tuMMGklRnc%2BHwOtHhLSWG8QF9DrHRFgMww%2BWxtMaxMoE%2F%2BiA96CAKEC%2FhdEYpelM%2BE%3D\" rel=\"nofollow\">\u300aJava\u5f00\u53d1\u624b\u518c\uff08\u5d69\u5c71\u7248\uff09\u300b\u6700\u65b0\u53d1\u5e03\uff0c\u901f\u901f\u4e0b\u8f7d\uff01<\/a><\/p>\n<p>\u89c9\u5f97\u4e0d\u9519\uff0c\u522b\u5fd8\u4e86\u968f\u624b\u70b9\u8d5e+\u8f6c\u53d1\u54e6\uff01<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000042373121\">https:\/\/segmentfault.com\/a\/1190000042373121<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>SQLite \u662f\u4e00\u4e2a\u88ab\u5927\u5bb6\u4f4e\u4f30\u7684\u6570\u636e\u5e93\uff0c\u4f46\u6709\u4e9b\u4eba\u8ba4\u4e3a\u5b83\u662f\u4e00\u4e2a\u4e0d\u9002\u5408\u751f\u4ea7\u73af\u5883\u4f7f\u7528\u7684\u73a9\u5177\u6570\u636e\u5e93\u3002\u4e8b\u5b9e\u4e0a\uff0cSQLit [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[],"tags":[],"class_list":["post-10006311","post","type-post","status-publish","format-standard","hentry"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006311","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10006311"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006311\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10006311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10006311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10006311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}