\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86\u89e3\u51b3PostgreSQL Array\u4f7f\u7528\u4e2d\u7684\u4e00\u4e9b\u5c0f\u95ee\u9898\uff0c\u5177\u6709\u5f88\u597d\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u6709\u6240\u5e2e\u52a9\u3002\u4e00\u8d77\u8ddf\u968f\u5c0f\u7f16\u8fc7\u6765\u770b\u770b\u5427<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\u5728PostgreSQL \u4e2d\u53ef\u4ee5\u4f7f\u7528Array\u6570\u636e\u7ed3\u6784\uff0c\u4f8b\u5982<\/p>\n
\r\nselect array[1,2,3]; \r\nreturn {1,2,3}<\/pre>\n\u4f46\u662f\uff0c\u5982\u679c<\/p>\n
\r\nselect array[1,2,3][1]; --\u4f1a\u62a5\u9519 \r\nselect (select array[1,2,3])[1] --\u53ef\u4ee5\u4f7f\u7528<\/pre>\n\u90a3\u4e48\u5728\u7528\u6b63\u5219\u5339\u914d\u51fd\u6570 regexp_match \u5c31\u4f1a\u9047\u5230\u8fd9\u6837\u7684\u95ee\u9898\uff0c\u5982<\/p>\n
\r\nselect regexp_match('123-123', '(\\d+)-(\\d+)'); --return {123, 123}\r\nselect regexp_match('123-123', '(\\d+)-(\\d+)')[1]; --\u62a5\u9519<\/pre>\n\u4f46\u662f\uff0c\u5982\u679c\u4f60\u60f3\u83b7\u53d6\u5176\u4e2d\u4e00\u4e2a\u5143\u7d20\uff0c\u4f60\u5c31\u5f97\u4f7f\u7528\u5d4c\u5957\u67e5\u8be2\uff0c\u5982<\/p>\n
\r\nselect(select regexp_match('123-123', '(\\d+)-(\\d+)'))[1]; --return 123<\/pre>\n\u5176\u6b21\uff0c\u4f60\u5982\u679c\u8981\u7528regexp_matches \u52a0\u4e0a\u5168\u5c40\u641c\u7d22\uff0c\u53ef\u80fd\u4f1a\u751f\u6210\u591a\u884c\u6570\u636e\uff0c\u5982<\/p>\n
\r\nselect 'a', array(select regexp_matches('aa-aa', '(aa)+', 'g'));\r\n-- return 2 rows\r\na {aa}\r\na {aa}<\/pre>\n\u5408\u5e76\u4e3a\u4e00\u884c\uff0c\u9700\u8981array\u51fd\u6570<\/p>\n
\r\nselect 'a', array(select regexp_matches('aa-aa', '(aa)+', 'g'));\r\n--return \r\na {{aa},{aa}}<\/pre>\n\u53d6\u5176\u4e2d\u7684\u5143\u7d20<\/p>\n
\r\nselect a, b[1][1] from (select 'a' as a, array(select regexp_matches('aa-aa', '(aa)+', 'g')) as b) as c;\r\n--return \r\naa<\/pre>\n\u8865\u5145\uff1aPostgreSQL\u7684 array_to_string \u529f\u80fd<\/strong><\/span><\/div>\n\u5f00\u59cb<\/p>\n
\u7528 \u7b2c\u4e8c\u4e2a\u53c2\u6570\u8fde\u63a5\u6570\u7ec4\u5143\u7d20\uff0c\u4f8b\uff1a<\/p>\n
\r\npostgres=# select array_to_string (ARRAY[1,2,3],'##');\r\n array_to_string \r\n-----------------\r\n 1##2##3\r\n(1 row)\r\npostgres=# <\/pre>\n\u7ed3\u675f~<\/p>\n
\u4ee5\u4e0a\u4e3a\u4e2a\u4eba\u7ecf\u9a8c\uff0c\u5e0c\u671b\u80fd\u7ed9\u5927\u5bb6\u4e00\u4e2a\u53c2\u8003\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
\u5728PostgreSQL \u4e2d\u53ef\u4ee5\u4f7f\u7528Array\u6570\u636e\u7ed3\u6784\uff0c\u4f8b\u5982 select array[1,2,3]; retu […]<\/p>\n","protected":false},"author":1482,"featured_media":86881,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-210649","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/210649","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1482"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=210649"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/210649\/revisions"}],"predecessor-version":[{"id":210652,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/210649\/revisions\/210652"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/86881"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=210649"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=210649"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=210649"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}