{"id":4569,"date":"2019-11-22T14:37:56","date_gmt":"2019-11-22T06:37:56","guid":{"rendered":"https:\/\/www.xttblog.com\/?p=4569"},"modified":"2019-11-22T14:37:56","modified_gmt":"2019-11-22T06:37:56","slug":"%e8%a7%a3%e5%86%b3-postgresql-%e6%8a%a5-error-function-uuid_generate_v4-does-not-exist-%e5%bc%82%e5%b8%b8%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=4569","title":{"rendered":"\u89e3\u51b3 Postgresql \u62a5 ERROR: function uuid_generate_v4() does not exist \u5f02\u5e38\u95ee\u9898"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u6700\u8fd1\u6709\u4e00\u4e2a\u7cfb\u7edf\u7684 PostgreSQL \u6570\u636e\u5e93\u8fdb\u884c\u4e86\u8f6f\u4ef6\u5347\u7ea7\uff0c\u6ca1\u60f3\u5230\u5347\u7ea7\u540e\uff0c\u5728\u6267\u884c\u67d0\u4e9b SQL \u540e\u51fa\u73b0\u4e86 function uuid_generate_v4() does not exist \u5f02\u5e38\u3002\u672c\u6587\u7b80\u5355\u8bf4\u4e00\u4e0b\u8fd9\u4e2a\u5f02\u5e38\u5982\u4f55\u89e3\u51b3\uff01<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8be6\u7ec6\u7684\u5f02\u5e38\u4fe1\u606f\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">bad SQL grammar []; nested exception is org.postgresql.util.PSQLException: ERROR: function uuid_generate_v4() does not exist<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">nested exception is org.postgresql.util.PSQLException: ERROR: function uuid_generate_v4() does not exist<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6839\u636e\u8fd9\u4e2a\u9519\u8bef\u63d0\u793a\uff0c\u6211\u4eec\u5c31\u5e94\u8be5\u80fd\u770b\u51fa\u6765\u662f uuid_generate_v4 \u8fd9\u4e2a\u51fd\u6570\u4e0d\u5b58\u5728\u5bfc\u81f4\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5bfc\u81f4\u8fd9\u4e2a\u95ee\u9898\u7684\u539f\u56e0\u5c31\u662f\uff0cuuid_generate_v4() \u8fd9\u4e2a uuid \u51fd\u6570\u9ed8\u8ba4\u7684\u662f\u5728 Postgresql \u6269\u5c55\u4e2d\u7684\uff0c\u6570\u636e\u5e93\u8fc1\u79fb\u540e\uff0cextension \u6269\u5c55\u5c31\u6ca1\u6709\u4e86\uff0c\u9700\u8981\u91cd\u65b0\u5b89\u88c5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6709 3 \u79cd\u65b9\u6cd5\u53ef\u4ee5\u53ef\u4ee5\u8ba9 PostgreSQL \u6570\u636e\u5e93\u652f\u6301 uuid_generate_v4() \u6216 uuid_generate_v1() \u51fd\u6570\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u65b9\u6848\u4e00\uff1a\u5b89\u88c5 uuid-ossp \u6269\u5c55\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>create extension \"uuid-ossp\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u65b9\u6848\u4e8c\uff1a\u5728 PostgreSQL \u7684\u5b89\u88c5\u76ee\u5f55\u7684 share\/contrib \u4e0b\u9762\uff0c\u53ef\u4ee5\u627e\u5230 uuid-ossp.sql\uff0c\u6267\u884c psql -d pisces \u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>psql -d pisces -U postgres -f D:\/Service\/PostgreSQL\/9.6\/share\/contrib\/uuid-ossp.sql<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5176\u4e2d\u7684\u53c2\u6570\u89e3\u91ca\u5982\u4e0b\uff0c-d: \u6570\u636e\u5e93\u540d\uff1b-U: \u7528\u6237\u540d\uff1b-f: \u8981 import \u7684\u6587\u4ef6\u3002\u6267\u884c\u4e0a\u9762\u7684\u547d\u4ee4\u540e\uff0c\u51fa\u73b0\u591a\u4e2a CREATE FUNCTION \u4e14\u6ca1\u62a5\u9519\uff0c\u5219\u8868\u660e\u5b89\u88c5\u6210\u529f\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/mw690\/8fa5dcfcgy1g96t2zsmxbj20hv05cdfu.jpg\" alt=\"\" \/><figcaption>\u89e3\u51b3 Postgresql \u62a5 ERROR: function uuid_generate_v4() does not exist \u5f02\u5e38\u95ee\u9898<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u65b9\u6848\u4e09\uff1a\u81ea\u5b9a\u4e49\u51fd\u6570\uff0c\u66ff\u4ee3 uuid \u7684\u751f\u6210\u65b9\u6cd5\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>create or replace function random_str_uuid(integer)\nreturns text as\n$body$\n   select array_to_string(array(select substring('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' FROM (ceil(random()*62))::int FOR 1) FROM generate_series(1, $1)), '');\n$body$\nlanguage sql volatile;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0a\u5e0c\u671b\u80fd\u591f\u5e2e\u52a9\u5230\u5927\u5bb6\uff01<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=4569\">\u89e3\u51b3 Postgresql \u62a5 ERROR: function uuid_generate_v4() does not exist \u5f02\u5e38\u95ee\u9898<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u6709\u4e00\u4e2a\u7cfb\u7edf\u7684 PostgreSQL \u6570\u636e\u5e93\u8fdb\u884c\u4e86\u8f6f\u4ef6\u5347\u7ea7\uff0c\u6ca1\u60f3\u5230\u5347\u7ea7\u540e\uff0c\u5728\u6267\u884c\u67d0\u4e9b SQL \u540e\u51fa\u73b0\u4e86 fu [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[429,157,155,1410,681],"class_list":["post-4569","post","type-post","status-publish","format-standard","hentry","category-sql","tag-postgresql","tag-sql","tag-uuid","tag-681"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4569","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4569"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4569\/revisions"}],"predecessor-version":[{"id":4570,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4569\/revisions\/4570"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4569"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4569"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4569"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}