{"id":372156,"date":"2024-05-21T05:05:37","date_gmt":"2024-05-21T05:05:37","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=372156"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=372156","title":{"rendered":"<span>\u0421\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 (\u0447\u0430\u0441\u0442\u044c 2)<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u0440\u0430\u0437\u0431\u043e\u0440 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 PostgeSQL. \u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430\u043c \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u043c \u0441 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435\u043c <code>FOREIGN KEY<\/code> (<code>FK<\/code>). \u0427\u0430\u0441\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a \u0446\u0435\u043b\u0435\u0441\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043d\u0430 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u043e\u0441\u043d\u043e\u0432\u0435, \u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043d\u044f\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u0435 \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437.<\/p>\n<h3>\u0421\u043f\u0438\u0441\u043e\u043a \u0441\u0442\u0430\u0442\u0435\u0439<\/h3>\n<ul>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/articles\/800121\/\" rel=\"noopener noreferrer nofollow\">\u0421\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 (\u0447\u0430\u0441\u0442\u044c 1)<\/a><\/p>\n<\/li>\n<li>\n<p>\u0421\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 (\u0447\u0430\u0441\u0442\u044c 2)<\/p>\n<\/li>\n<\/ul>\n<h3>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0441\u0441\u044b\u043b\u043e\u0447\u043d\u043e\u0439 \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u0438<\/h3>\n<p>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0441\u0441\u044b\u043b\u043e\u0447\u043d\u043e\u0439 \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u2014 \u0433\u0438\u0431\u043a\u0438\u0439 \u0438 \u043c\u043e\u0449\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0439 \u0421\u0423\u0411\u0414 [1]. \u041e\u0441\u0442\u0430\u0432\u0438\u043c \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u043c\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 \u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0432\u0438\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c FK \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0421\u0423\u0411\u0414 \u0438\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u0434\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0411\u0414 \u044d\u0432\u043e\u043b\u044e\u0446\u0438\u043e\u043d\u0438\u0440\u0443\u0435\u0442, \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0432\u043d\u043e\u0441\u0438\u043c\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u043c\u0435\u043d\u044f\u0442\u044c \u0438\u0445 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a \u0434\u043b\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u0441\u0441\u044b\u043b\u043e\u0447\u043d\u043e\u0439 \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u0438.<\/p>\n<h4>\u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0439\u0441\u044f \u0438 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445<\/h4>\n<p>\u0422\u0438\u043f\u044b \u043a\u043e\u043b\u043e\u043d\u043e\u043a \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u043c\u0441\u044f \u0438 \u0446\u0435\u043b\u0435\u0432\u043e\u043c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0442\u044c. \u041a\u043e\u043b\u043e\u043d\u043a\u0430 \u0441 \u0442\u0438\u043f\u043e\u043c <code>integer<\/code> \u0434\u043e\u043b\u0436\u043d\u0430 \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u043e\u043b\u043e\u043d\u043a\u0443 \u0441 \u0442\u0438\u043f\u043e\u043c <code>integer<\/code>. \u042d\u0442\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043b\u0438\u0448\u043d\u0438\u0435 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u0438 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0421\u0423\u0411\u0414 \u0438 \u0432 \u043a\u043e\u0434\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0441\u043d\u0438\u0436\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0448\u0438\u0431\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0438\u0437-\u0437\u0430 \u043d\u0435\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c. <\/p>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0437\u0440\u0430\u0437\u0438\u0442\u044c, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0447\u0442\u043e\u0431\u044b \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u043c\u0441\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 \u0442\u0438\u043f\u044b \u043a\u043e\u043b\u043e\u043d\u043e\u043a \u0431\u044b\u043b\u0438 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b \u0438 \u043d\u0435 \u043c\u0435\u043d\u044c\u0448\u0435, \u0447\u0435\u043c \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u043c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u043b\u043e\u043d\u043a\u0430 \u0441 \u0442\u0438\u043f\u043e\u043c <code>bigint<\/code> \u043c\u043e\u0436\u0435\u0442 \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u043e\u043b\u043e\u043d\u043a\u0443 \u0441 \u0442\u0438\u043f\u043e\u043c <code>integer<\/code>. \u0422\u0430\u043a \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u0440\u0430\u0437\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043f\u0430\u0434\u0430\u0442\u044c \u0432 \u043a\u043e\u0434 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u0440\u0438 \u0430\u0432\u0442\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0435\u0439.<\/p>\n<p><strong>\u0417\u0430\u0434\u0430\u0447\u0430:<\/strong> \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 \u043a\u043e\u043b\u043e\u043d\u043e\u043a \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u0438 \u0446\u0435\u043b\u0435\u0432\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445.<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0439\u0441\u044f \u0438 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">-- \u043a\u043e\u043b\u043e\u043d\u043a\u0430 id \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u043c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 integer, \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u043c\u0441\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438  -- \u043a\u043e\u043b\u043e\u043d\u043a\u0430 fk1001_2_id bigint  -- \u0446\u0435\u043b\u0435\u0432\u043e\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 (\u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a)  DROP TABLE IF EXISTS public.fk1001_2 CASCADE; CREATE TABLE public.fk1001_2 (     id    integer GENERATED ALWAYS AS IDENTITY NOT NULL,     value text NOT NULL,     CONSTRAINT fk1001_2_pk PRIMARY KEY (id, value) );  -- \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0435\u0441\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 DROP TABLE IF EXISTS public.fk1001_2_fk; CREATE TABLE public.fk1001_2_fk (     fk1001_2_id bigint NOT NULL,     value text NOT NULL,     CONSTRAINT fk1001_2_fk_fk1001_2 FOREIGN KEY (fk1001_2_id, value)          REFERENCES public.fk1001_2(id, value) ); <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0439\u0441\u044f \u0438 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">WITH -- \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f FK \u0441 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u043d\u0438\u0445 \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u044b fk_with_attributes AS (         SELECT             c.conname as fk_name,             c.conrelid,             c.confrelid,             fk_conkey.conkey_order AS att_order,             fk_conkey.conkey_number,             fk_confkey.confkey_number,             rel_att.attname AS rel_att_name,             rel_att.atttypid AS rel_att_type_id,             rel_att.atttypmod AS rel_att_type_mod,             rel_att.attnotnull AS rel_att_notnull,             frel_att.attname AS frel_att_name,             frel_att.atttypid AS frel_att_type_id,             frel_att.atttypmod AS frel_att_type_mod,             frel_att.attnotnull AS frel_att_notnull         FROM pg_catalog.pg_constraint AS c             CROSS JOIN LATERAL UNNEST(c.conkey) WITH ORDINALITY AS fk_conkey(conkey_number, conkey_order)             LEFT JOIN LATERAL UNNEST(c.confkey) WITH ORDINALITY AS fk_confkey(confkey_number, confkey_order)                 ON fk_conkey.conkey_order = fk_confkey.confkey_order             LEFT JOIN pg_catalog.pg_attribute AS rel_att                 ON rel_att.attrelid = c.conrelid AND rel_att.attnum = fk_conkey.conkey_number             LEFT JOIN pg_catalog.pg_attribute AS frel_att                 ON frel_att.attrelid = c.confrelid AND frel_att.attnum = fk_confkey.confkey_number         WHERE c.contype IN ('f')     ) SELECT     c.fk_name,       -- \u043d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f fk     r_from.relname,  -- \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0435\u0441\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435     c.rel_att_names, -- \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u043c\u0441\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438     r_to.relname,    -- \u0446\u0435\u043b\u0435\u0441\u043e\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435     c.frel_att_names -- \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u043c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 FROM (     -- \u043e\u0442\u0431\u0438\u0440\u0430\u0435\u043c FK, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0441\u0442\u044c \u0440\u0430\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u043a\u043e\u043b\u043e\u043d\u043e\u043a     SELECT         fk_name,         conrelid,         confrelid,         array_agg (rel_att_name order by att_order ) as rel_att_names,         array_agg (frel_att_name order by att_order ) as frel_att_names     FROM fk_with_attributes     WHERE         ((rel_att_type_id &lt;> frel_att_type_id) OR (rel_att_type_mod &lt;> frel_att_type_mod))     GROUP BY 1, 2, 3 ) AS c     INNER JOIN pg_catalog.pg_class AS r_from         ON r_from.oid = c.conrelid     INNER JOIN pg_catalog.pg_class AS r_to         ON r_to.oid = c.confrelid <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h4>\u0412 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0439\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u043b\u043e\u043d\u043e\u043a FK \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f NULL<\/h4>\n<p>\u0417\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442, \u0447\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 FK \u0438 \u0431\u0430\u0437\u0430 \u043a\u0430\u043a-\u0442\u043e \u0441\u0430\u043c\u0430 \u0432\u0441\u0451 \u043f\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u0435\u0442. \u0421\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u044f\u0441\u044c \u0432\u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0438\u0445 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f\u043c, \u0442\u0430\u043a\u0438\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438, \u043d\u0435 \u0440\u0435\u0434\u043a\u043e \u043d\u0435 \u043f\u044b\u0442\u0430\u044e\u0442\u0441\u044f \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u0445, \u0430 \u043e\u0442\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043e\u0442 FK \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0411\u0414, \u043f\u043e\u043b\u0430\u0433\u0430\u044f \u0438\u0445 \u0441\u043b\u043e\u0436\u043d\u044b\u043c\u0438 \u0438\u043b\u0438 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u043c\u0438. <\/p>\n<p>\u041f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 FK \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0435\u0433\u043e \u0438\u0437 \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432. \u041e\u0434\u043d\u0430\u043a\u043e \u0435\u0441\u043b\u0438 FK \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043a\u043e\u043b\u043e\u043d\u043e\u043a \u0438 \u0447\u0430\u0441\u0442\u044c \u0438\u0437 \u043d\u0438\u0445 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 NULL, \u0432 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043c\u043e\u0433\u0443\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430.  <\/p>\n<p>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0441 NULL \u0438\u043c\u0435\u0435\u0442 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0437\u043d\u0430\u0442\u044c \u0438 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c [2]. \u0414\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f FK \u0441 \u043a\u043e\u043b\u043e\u043d\u043a\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c NULL, \u0435\u0441\u0442\u044c \u0443\u0442\u043e\u0447\u043d\u044f\u044e\u0449\u0438\u0435 \u043a\u043b\u044e\u0447\u0438 &#8212; <code>MATCH SIMPLE<\/code> (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e) \u0438 <code>MATCH FULL<\/code> (<code>MATCH PARTIAL<\/code> \u0432 PostgreSQL \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d) [3]. <\/p>\n<p><strong>\u0417\u0430\u0434\u0430\u0447\u0430:<\/strong> \u043d\u0430\u0439\u0442\u0438 FK, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0439\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 NULL, \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0442\u0438\u043f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u043d\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0432 <code>MATCH FULL<\/code>.<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u043b\u0443\u0447\u0430\u044f, \u043a\u043e\u0433\u0434\u0430 \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0439\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u043b\u043e\u043d\u043e\u043a FK \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f NULL<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">-- \u0446\u0435\u043b\u0435\u0432\u043e\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 (\u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a)  DROP TABLE IF EXISTS public.fk1002_2 CASCADE; CREATE TABLE public.fk1002_2 (     id    integer NOT NULL,     value varchar(10) NOT NULL,     CONSTRAINT fk1002_2_pk PRIMARY KEY (id, value) );  -- \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a\u0430 INSERT INTO public.fk1002_2 (id, value) VALUES (10, '10'); INSERT INTO public.fk1002_2 (id, value) VALUES (20, '20');  -- \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0435\u0441\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 DROP TABLE IF EXISTS public.fk1002_2_fk; CREATE TABLE public.fk1002_2_fk (     fk1002_2_id integer NOT NULL,     fk1002_2_value varchar(10),     CONSTRAINT fk1002_2_fk_fk1002_2        FOREIGN KEY (fk1002_2_id, fk1002_2_value)          REFERENCES public.fk1002_2 (id, value) );  -- \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 -- \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043f\u043e\u043b\u0435 fk1002_2_value \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c NULL -- \u043e\u0431\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 -- \u0435\u0441\u043b\u0438 \u0431\u044b \u0434\u043b\u044f CONSTRAINT fk1002_2_fk_fk1002_2 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0438 MATCH FULL -- \u0442\u043e\u0433\u0434\u0430 \u0432\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u043d\u0435 \u0431\u044b\u043b\u0430 \u0431\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 INSERT INTO public.fk1002_2_fk (fk1002_2_id, fk1002_2_value) VALUES (20, '20'); INSERT INTO public.fk1002_2_fk (fk1002_2_id, fk1002_2_value) VALUES (30, NULL); <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0434\u043b\u044f \u0441\u043b\u0443\u0447\u0430\u044f, \u043a\u043e\u0433\u0434\u0430 \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0439\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u043b\u043e\u043d\u043e\u043a FK \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f NULL<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">WITH -- \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f FK \u0441 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u043d\u0438\u0445 \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u044b fk_with_attributes AS (         SELECT             c.conname as fk_name,             c.conrelid,             c.confrelid,             c.confmatchtype,             fk_conkey.conkey_order AS att_order,             fk_conkey.conkey_number,             fk_confkey.confkey_number,             rel_att.attname AS rel_att_name,             rel_att.atttypid AS rel_att_type_id,             rel_att.atttypmod AS rel_att_type_mod,             rel_att.attnotnull AS rel_att_notnull,             frel_att.attname AS frel_att_name,             frel_att.atttypid AS frel_att_type_id,             frel_att.atttypmod AS frel_att_type_mod,             frel_att.attnotnull AS frel_att_notnull         FROM pg_catalog.pg_constraint AS c             CROSS JOIN LATERAL UNNEST(c.conkey) WITH ORDINALITY AS fk_conkey(conkey_number, conkey_order)             LEFT JOIN LATERAL UNNEST(c.confkey) WITH ORDINALITY AS fk_confkey(confkey_number, confkey_order)                 ON fk_conkey.conkey_order = fk_confkey.confkey_order             LEFT JOIN pg_catalog.pg_attribute AS rel_att                 ON rel_att.attrelid = c.conrelid AND rel_att.attnum = fk_conkey.conkey_number             LEFT JOIN pg_catalog.pg_attribute AS frel_att                 ON frel_att.attrelid = c.confrelid AND frel_att.attnum = fk_confkey.confkey_number         WHERE c.contype IN ('f')     ) SELECT     c.fk_name,       -- \u043d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f fk     r_from.relname,  -- \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0435\u0441\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435     c.rel_att_names  -- nullable \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u043c\u0441\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 FROM (     -- \u043e\u0442\u0431\u0438\u0440\u0430\u0435\u043c FK, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0441\u0442\u044c \u0440\u0430\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u043a\u043e\u043b\u043e\u043d\u043e\u043a     SELECT         fk_name,         conrelid,         confrelid,         array_agg (rel_att_name order by att_order ) as rel_att_names     FROM fk_with_attributes     WHERE         (rel_att_notnull IS NOT TRUE)         AND confmatchtype NOT IN ('f')     GROUP BY 1, 2, 3 ) AS c     INNER JOIN pg_catalog.pg_class AS r_from         ON r_from.oid = c.conrelid<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h4>FK \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u0438\u043b\u0438 \u0443\u0441\u0442\u0430\u0440\u0435\u043b\u0438<\/h4>\n<p>\u0421\u0438\u0442\u0443\u0430\u0446\u0438\u044f, \u043a\u043e\u0433\u0434\u0430 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0430\u044f\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e FK \u043d\u0430 \u0446\u0435\u043b\u0435\u0432\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0430\u043d\u0430\u043b\u043e\u0433\u043e\u0432 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0434\u0432\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0442\u043e\u0432\u0430\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0430\u043c\u0438 \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0430, \u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0435 \u043f\u043e\u043b\u044f.<\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0439\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0434\u0432\u0430 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043e\u0434\u043d\u0443 \u0446\u0435\u043b\u0435\u0432\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0438\u043c\u0435\u044e\u0442 \u043f\u043e\u043b\u043d\u043e\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432, \u044d\u0442\u043e \u044f\u0432\u043d\u044b\u0439 \u043f\u0440\u0438\u0437\u043d\u0430\u043a \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f FK. \u0415\u0441\u043b\u0438 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432, \u044d\u0442\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0433\u043e \u043e\u0448\u0438\u0431\u043e\u0447\u043d\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f FK \u0438\u043b\u0438 \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0435\u0433\u043e FK. <\/p>\n<p>\u041e\u0433\u043e\u0432\u043e\u0440\u0438\u043c\u0441\u044f \u0441\u0440\u0430\u0437\u0443, \u0447\u0442\u043e \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 FK \u0437\u0430\u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0442\u0441\u044f \u043f\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c, \u0435\u0441\u0442\u044c, \u043e\u0434\u043d\u0430\u043a\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u043e\u043d\u0438 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u0436\u0435, \u0447\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439. <\/p>\n<p><strong>\u0417\u0430\u0434\u0430\u0447\u0430:<\/strong> \u043d\u0430\u0439\u0442\u0438 \u043f\u0430\u0440\u044b FK, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043c\u0435\u044e\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0443\u044e\u0441\u044f \u0438 \u0446\u0435\u043b\u0435\u0432\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0439\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0443 \u043d\u0438\u0445 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0442\u0441\u044f.<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u043b\u0443\u0447\u0430\u044f, \u043a\u043e\u0433\u0434\u0430 FK \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u0438\u043b\u0438 \u0443\u0441\u0442\u0430\u0440\u0435\u043b\u0438<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">DROP TABLE IF EXISTS public.fk1010_1 CASCADE; CREATE TABLE public.fk1010_1 (     id    integer NOT NULL,     i1    integer NOT NULL,     i2    integer NOT NULL,     CONSTRAINT fk1010_1_pk PRIMARY KEY (id),     CONSTRAINT fk1010_1_unique_id_i1 UNIQUE (id, i1),     CONSTRAINT fk1010_1_unique_id_i2 UNIQUE (id, i2),     CONSTRAINT fk1010_1_unique_i2 UNIQUE (i2) );  DROP TABLE IF EXISTS public.fk1010_1_fk; CREATE TABLE public.fk1010_1_fk (     id    integer GENERATED ALWAYS AS IDENTITY NOT NULL,     fk1010_1_id integer NOT NULL,     fk1010_1_i1 integer NOT NULL,     fk1010_1_i2 integer NOT NULL,     CONSTRAINT fk1010_1_fk_pk PRIMARY KEY (id),     CONSTRAINT fk1010_1_fk_fk1010_1_id FOREIGN KEY (fk1010_1_id) REFERENCES public.fk1010_1(id),     CONSTRAINT fk1010_1_fk_fk1010_1_id_i1 FOREIGN KEY (fk1010_1_id, fk1010_1_i1) REFERENCES public.fk1010_1(id, i1),     CONSTRAINT fk1010_1_fk_fk1010_1_id_i2 FOREIGN KEY (fk1010_1_id, fk1010_1_i2) REFERENCES public.fk1010_1(id, i2),     CONSTRAINT fk1010_1_fk_fk1010_1_id_i2_copy FOREIGN KEY (fk1010_1_id, fk1010_1_i2) REFERENCES public.fk1010_1(id, i2),     CONSTRAINT fk1010_1_fk_fk1010_1_i2 FOREIGN KEY (fk1010_1_i2) REFERENCES public.fk1010_1(i2) );  -- FK  \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b -- fk1010_1_fk_fk1010_1_id_i2 \u0438 fk1010_1_fk_fk1010_1_id_i2_copy  -- FK \u0438\u043c\u0435\u044e\u0442 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c -- fk1010_1_fk_fk1010_1_id \u0438 fk1010_1_fk_fk1010_1_id_i1 -- fk1010_1_fk_fk1010_1_id \u0438 fk1010_1_fk_fk1010_1_id_i2 -- fk1010_1_fk_fk1010_1_id \u0438 fk1010_1_fk_fk1010_1_id_i2_copy -- fk1010_1_fk_fk1010_1_id_i1 \u0438 fk1010_1_fk_fk1010_1_id_i2 -- fk1010_1_fk_fk1010_1_id_i1 \u0438 fk1010_1_fk_fk1010_1_id_i2_copy -- fk1010_1_fk_fk1010_1_i2 \u0438 fk1010_1_fk_fk1010_1_id_i2 -- fk1010_1_fk_fk1010_1_i2 \u0438 fk1010_1_fk_fk1010_1_id_i2_copy <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u043b\u0443\u0447\u0430\u044f, \u043a\u043e\u0433\u0434\u0430 FK \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">WITH -- \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f FK \u0441 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u043d\u0438\u0445 \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u044b fk_with_attributes AS (         SELECT             c.conname as fk_name,             c.conrelid,             c.confrelid,             fk_conkey.conkey_order AS att_order,             fk_conkey.conkey_number,             fk_confkey.confkey_number,             rel_att.attname AS rel_att_name,             rel_att.atttypid AS rel_att_type_id,             rel_att.atttypmod AS rel_att_type_mod,             rel_att.attnotnull AS rel_att_notnull,             frel_att.attname AS frel_att_name,             frel_att.atttypid AS frel_att_type_id,             frel_att.atttypmod AS frel_att_type_mod,             frel_att.attnotnull AS frel_att_notnull         FROM pg_catalog.pg_constraint AS c             CROSS JOIN LATERAL UNNEST(c.conkey) WITH ORDINALITY AS fk_conkey(conkey_number, conkey_order)             LEFT JOIN LATERAL UNNEST(c.confkey) WITH ORDINALITY AS fk_confkey(confkey_number, confkey_order)                 ON fk_conkey.conkey_order = fk_confkey.confkey_order             LEFT JOIN pg_catalog.pg_attribute AS rel_att                 ON rel_att.attrelid = c.conrelid AND rel_att.attnum = fk_conkey.conkey_number             LEFT JOIN pg_catalog.pg_attribute AS frel_att                 ON frel_att.attrelid = c.confrelid AND frel_att.attnum = fk_confkey.confkey_number         WHERE c.contype IN ('f')     ),     --     fk_with_attributes_grouped AS (         SELECT             fk_name,             conrelid,             confrelid,             array_agg (rel_att_name order by att_order) as rel_att_names,             array_agg (frel_att_name order by att_order) as frel_att_names         FROM fk_with_attributes         GROUP BY 1, 2, 3     ) SELECT     r_from.relname,  -- \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0435\u0441\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435     c1.fk_name,      -- \u043d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f fk     c2.fk_name       -- \u043d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f fk (\u043f\u043e\u0442\u0435\u043d\u0446\u0438\u043b\u044c\u043d\u044b\u0439 \u0434\u0443\u0431\u043b\u044c) FROM fk_with_attributes_grouped AS c1     INNER JOIN fk_with_attributes_grouped AS c2 ON c1.fk_name &lt; c2.fk_name          AND c1.conrelid = c2.conrelid AND c1.confrelid = c2.confrelid         AND c1.rel_att_names = c2.rel_att_names     INNER JOIN pg_catalog.pg_class AS r_from ON r_from.oid = c1.conrelid<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u043b\u0443\u0447\u0430\u044f, \u043a\u043e\u0433\u0434\u0430 FK \u0438\u043c\u0435\u044e\u0442 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">WITH -- \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f FK \u0441 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u043d\u0438\u0445 \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u044b fk_with_attributes AS (         SELECT             c.conname as fk_name,             c.conrelid,             c.confrelid,             fk_conkey.conkey_order AS att_order,             fk_conkey.conkey_number,             fk_confkey.confkey_number,             rel_att.attname AS rel_att_name,             rel_att.atttypid AS rel_att_type_id,             rel_att.atttypmod AS rel_att_type_mod,             rel_att.attnotnull AS rel_att_notnull,             frel_att.attname AS frel_att_name,             frel_att.atttypid AS frel_att_type_id,             frel_att.atttypmod AS frel_att_type_mod,             frel_att.attnotnull AS frel_att_notnull         FROM pg_catalog.pg_constraint AS c             CROSS JOIN LATERAL UNNEST(c.conkey) WITH ORDINALITY AS fk_conkey(conkey_number, conkey_order)             LEFT JOIN LATERAL UNNEST(c.confkey) WITH ORDINALITY AS fk_confkey(confkey_number, confkey_order)                 ON fk_conkey.conkey_order = fk_confkey.confkey_order             LEFT JOIN pg_catalog.pg_attribute AS rel_att                 ON rel_att.attrelid = c.conrelid AND rel_att.attnum = fk_conkey.conkey_number             LEFT JOIN pg_catalog.pg_attribute AS frel_att                 ON frel_att.attrelid = c.confrelid AND frel_att.attnum = fk_confkey.confkey_number         WHERE c.contype IN ('f')     ),     --     fk_with_attributes_grouped AS (         SELECT             fk_name,             conrelid,             confrelid,             array_agg (rel_att_name order by att_order) as rel_att_names,             array_agg (frel_att_name order by att_order) as frel_att_names         FROM fk_with_attributes         GROUP BY 1, 2, 3     ) SELECT     r_from.relname,  -- \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0435\u0441\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435     c1.fk_name,      -- \u043d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f fk     c2.fk_name       -- \u043d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f fk (\u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c) FROM fk_with_attributes_grouped AS c1     INNER JOIN fk_with_attributes_grouped AS c2 ON c1.fk_name &lt; c2.fk_name          AND c1.conrelid = c2.conrelid AND c1.confrelid = c2.confrelid         AND (c1.rel_att_names &amp;&amp; c2.rel_att_names)     INNER JOIN pg_catalog.pg_class AS r_from ON r_from.oid = c1.conrelid<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h4>\u041e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043d\u0435 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0432 FK<\/h4>\n<p>\u041a\u0430\u043a \u0443\u0436\u0435 \u043e\u0442\u043c\u0435\u0447\u0430\u043b\u0438 \u0432\u044b\u0448\u0435, \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0441\u0441\u044b\u043b\u043e\u0447\u043d\u043e\u0439 \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u2014 \u0433\u0438\u0431\u043a\u0438\u0439 \u0438 \u043c\u043e\u0449\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0434\u0430\u043d\u043d\u044b\u0445. \u041a\u0430\u043a \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435, \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0441\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0441\u0432\u044f\u0437\u0430\u043d\u044b \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>FK<\/code>, \u0442.\u043e. \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0439 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u044e\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0446\u0435\u043b\u0435\u0432\u044b\u0445 \u0438\u043b\u0438 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0438\u0445\u0441\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438 \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u0435 \u0441 \u043d\u043e\u0432\u044b\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c \u0446\u0435\u043b\u0435\u0441\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 <code>FK<\/code>. \u0427\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c?<\/p>\n<ul>\n<li>\n<p>\u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0449\u0438\u0435\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 (\u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u0442\u0438\u043f\u0430 liquibase, \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u043b\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u043b\u0430\u0433\u0438\u043d\u043e\u0432 \u0438\u043b\u0438 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439);<\/p>\n<\/li>\n<li>\n<p>\u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0436\u0435 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0438\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u043e\u0448\u0438\u0431\u043e\u0447\u043d\u043e, \u043d\u043e \u043d\u0435 \u0431\u044b\u043b\u0438 \u0441\u0432\u043e\u0435\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0443\u0434\u0430\u043b\u0435\u043d\u044b (\u043e\u043f\u0435\u0447\u0430\u0442\u043a\u0438 \u0432 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f\u0445, \u043e\u0442\u0433\u043e\u043b\u043e\u0441\u043a\u0438 \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430);<\/p>\n<\/li>\n<li>\n<p>\u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f ETL (\u0440\u0430\u0437\u043c\u0435\u0440 \u0442\u0430\u043a\u0438\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u043c, \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0446\u0435\u043b\u0435\u0441\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e \u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u0434\u043b\u044f \u044d\u0442\u0438\u0445 \u0446\u0435\u043b\u0435\u0439).<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0417\u0430\u0434\u0430\u0447\u0430:<\/strong> \u043d\u0430\u0439\u0442\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 FK.<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0442\u0430\u0431\u043b\u0438\u0446 \u043d\u0435 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0432 FK<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">SELECT n.nspname,  -- \u0441\u0445\u0435\u043c\u0430 t.relname   -- \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 FROM pg_catalog.pg_class AS t     INNER JOIN pg_catalog.pg_namespace AS n          ON t.relnamespace = n.oid WHERE     relkind IN ('r', 'p')     AND t.oid NOT IN (SELECT conrelid FROM pg_catalog.pg_constraint WHERE contype IN ('f'))     AND t.oid NOT IN (SELECT confrelid FROM pg_catalog.pg_constraint WHERE contype IN ('f'))     AND n.nspname NOT IN ('information_schema', 'pg_catalog')      AND n.nspname NOT LIKE 'pg_toast%'<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h4>\u0421\u0441\u044b\u043b\u043a\u0438<\/h4>\n<p>[1] <a href=\"https:\/\/postgrespro.ru\/docs\/postgresql\/16\/ddl-constraints#DDL-CONSTRAINTS-FK\" rel=\"noopener noreferrer nofollow\">https:\/\/postgrespro.ru\/docs FK<\/a><\/p>\n<p>[2] <a href=\"https:\/\/postgrespro.ru\/docs\/postgresql\/16\/functions-comparison\" rel=\"noopener noreferrer nofollow\">https:\/\/postgrespo.ru\/docs functions comparison<\/a><\/p>\n<p>[3] <a href=\"https:\/\/postgrespro.ru\/docs\/postgresql\/16\/sql-createtable\" rel=\"noopener noreferrer nofollow\">https:\/\/postgrespro.ru\/docs CREATE TABLE<\/a> (\u0441\u043c. \u043f\u043e \u043f\u043e\u0438\u0441\u043a\u0443 <code>MATCH FULL<\/code>)<\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u0435 \u0432\u044b\u0448\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438\u00a0<a href=\"https:\/\/github.com\/sdblist\/db_verifier\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/sdblist\/db_verifier<\/a> <\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/803841\/\"> https:\/\/habr.com\/ru\/articles\/803841\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u0440\u0430\u0437\u0431\u043e\u0440 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 PostgeSQL. \u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430\u043c \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u043c \u0441 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435\u043c <code>FOREIGN KEY<\/code> (<code>FK<\/code>). \u0427\u0430\u0441\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a \u0446\u0435\u043b\u0435\u0441\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043d\u0430 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u043e\u0441\u043d\u043e\u0432\u0435, \u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043d\u044f\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u0435 \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437.<\/p>\n<h3>\u0421\u043f\u0438\u0441\u043e\u043a \u0441\u0442\u0430\u0442\u0435\u0439<\/h3>\n<ul>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/articles\/800121\/\" rel=\"noopener noreferrer nofollow\">\u0421\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 (\u0447\u0430\u0441\u0442\u044c 1)<\/a><\/p>\n<\/li>\n<li>\n<p>\u0421\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 (\u0447\u0430\u0441\u0442\u044c 2)<\/p>\n<\/li>\n<\/ul>\n<h3>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0441\u0441\u044b\u043b\u043e\u0447\u043d\u043e\u0439 \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u0438<\/h3>\n<p>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0441\u0441\u044b\u043b\u043e\u0447\u043d\u043e\u0439 \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u2014 \u0433\u0438\u0431\u043a\u0438\u0439 \u0438 \u043c\u043e\u0449\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0439 \u0421\u0423\u0411\u0414 [1]. \u041e\u0441\u0442\u0430\u0432\u0438\u043c \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u043c\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 \u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0432\u0438\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c FK \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0421\u0423\u0411\u0414 \u0438\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u0434\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0411\u0414 \u044d\u0432\u043e\u043b\u044e\u0446\u0438\u043e\u043d\u0438\u0440\u0443\u0435\u0442, \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0432\u043d\u043e\u0441\u0438\u043c\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u043c\u0435\u043d\u044f\u0442\u044c \u0438\u0445 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a \u0434\u043b\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u0441\u0441\u044b\u043b\u043e\u0447\u043d\u043e\u0439 \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u0438.<\/p>\n<h4>\u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0439\u0441\u044f \u0438 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445<\/h4>\n<p>\u0422\u0438\u043f\u044b \u043a\u043e\u043b\u043e\u043d\u043e\u043a \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u043c\u0441\u044f \u0438 \u0446\u0435\u043b\u0435\u0432\u043e\u043c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0442\u044c. \u041a\u043e\u043b\u043e\u043d\u043a\u0430 \u0441 \u0442\u0438\u043f\u043e\u043c <code>integer<\/code> \u0434\u043e\u043b\u0436\u043d\u0430 \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u043e\u043b\u043e\u043d\u043a\u0443 \u0441 \u0442\u0438\u043f\u043e\u043c <code>integer<\/code>. \u042d\u0442\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043b\u0438\u0448\u043d\u0438\u0435 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u0438 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0421\u0423\u0411\u0414 \u0438 \u0432 \u043a\u043e\u0434\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0441\u043d\u0438\u0436\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0448\u0438\u0431\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0438\u0437-\u0437\u0430 \u043d\u0435\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c. <\/p>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0437\u0440\u0430\u0437\u0438\u0442\u044c, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0447\u0442\u043e\u0431\u044b \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u043c\u0441\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 \u0442\u0438\u043f\u044b \u043a\u043e\u043b\u043e\u043d\u043e\u043a \u0431\u044b\u043b\u0438 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b \u0438 \u043d\u0435 \u043c\u0435\u043d\u044c\u0448\u0435, \u0447\u0435\u043c \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u043c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u043b\u043e\u043d\u043a\u0430 \u0441 \u0442\u0438\u043f\u043e\u043c <code>bigint<\/code> \u043c\u043e\u0436\u0435\u0442 \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u043e\u043b\u043e\u043d\u043a\u0443 \u0441 \u0442\u0438\u043f\u043e\u043c <code>integer<\/code>. \u0422\u0430\u043a \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u0440\u0430\u0437\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043f\u0430\u0434\u0430\u0442\u044c \u0432 \u043a\u043e\u0434 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u0440\u0438 \u0430\u0432\u0442\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0435\u0439.<\/p>\n<p><strong>\u0417\u0430\u0434\u0430\u0447\u0430:<\/strong> \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 \u043a\u043e\u043b\u043e\u043d\u043e\u043a \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u0438 \u0446\u0435\u043b\u0435\u0432\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445.<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0439\u0441\u044f \u0438 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">-- \u043a\u043e\u043b\u043e\u043d\u043a\u0430 id \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u043c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 integer, \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u043c\u0441\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438  -- \u043a\u043e\u043b\u043e\u043d\u043a\u0430 fk1001_2_id bigint  -- \u0446\u0435\u043b\u0435\u0432\u043e\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 (\u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a)  DROP TABLE IF EXISTS public.fk1001_2 CASCADE; CREATE TABLE public.fk1001_2 (     id    integer GENERATED ALWAYS AS IDENTITY NOT NULL,     value text NOT NULL,     CONSTRAINT fk1001_2_pk PRIMARY KEY (id, value) );  -- \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0435\u0441\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 DROP TABLE IF EXISTS public.fk1001_2_fk; CREATE TABLE public.fk1001_2_fk (     fk1001_2_id bigint NOT NULL,     value text NOT NULL,     CONSTRAINT fk1001_2_fk_fk1001_2 FOREIGN KEY (fk1001_2_id, value)          REFERENCES public.fk1001_2(id, value) ); <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0439\u0441\u044f \u0438 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">WITH -- \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f FK \u0441 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u043d\u0438\u0445 \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u044b fk_with_attributes AS (         SELECT             c.conname as fk_name,             c.conrelid,             c.confrelid,             fk_conkey.conkey_order AS att_order,             fk_conkey.conkey_number,             fk_confkey.confkey_number,             rel_att.attname AS rel_att_name,             rel_att.atttypid AS rel_att_type_id,             rel_att.atttypmod AS rel_att_type_mod,             rel_att.attnotnull AS rel_att_notnull,             frel_att.attname AS frel_att_name,             frel_att.atttypid AS frel_att_type_id,             frel_att.atttypmod AS frel_att_type_mod,             frel_att.attnotnull AS frel_att_notnull         FROM pg_catalog.pg_constraint AS c             CROSS JOIN LATERAL UNNEST(c.conkey) WITH ORDINALITY AS fk_conkey(conkey_number, conkey_order)             LEFT JOIN LATERAL UNNEST(c.confkey) WITH ORDINALITY AS fk_confkey(confkey_number, confkey_order)                 ON fk_conkey.conkey_order = fk_confkey.confkey_order             LEFT JOIN pg_catalog.pg_attribute AS rel_att                 ON rel_att.attrelid = c.conrelid AND rel_att.attnum = fk_conkey.conkey_number             LEFT JOIN pg_catalog.pg_attribute AS frel_att                 ON frel_att.attrelid = c.confrelid AND frel_att.attnum = fk_confkey.confkey_number         WHERE c.contype IN ('f')     ) SELECT     c.fk_name,       -- \u043d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f fk     r_from.relname,  -- \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0435\u0441\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435     c.rel_att_names, -- \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u043c\u0441\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438     r_to.relname,    -- \u0446\u0435\u043b\u0435\u0441\u043e\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435     c.frel_att_names -- \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u043c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 FROM (     -- \u043e\u0442\u0431\u0438\u0440\u0430\u0435\u043c FK, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0441\u0442\u044c \u0440\u0430\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u043a\u043e\u043b\u043e\u043d\u043e\u043a     SELECT         fk_name,         conrelid,         confrelid,         array_agg (rel_att_name order by att_order ) as rel_att_names,         array_agg (frel_att_name order by att_order ) as frel_att_names     FROM fk_with_attributes     WHERE         ((rel_att_type_id &lt;> frel_att_type_id) OR (rel_att_type_mod &lt;> frel_att_type_mod))     GROUP BY 1, 2, 3 ) AS c     INNER JOIN pg_catalog.pg_class AS r_from         ON r_from.oid = c.conrelid     INNER JOIN pg_catalog.pg_class AS r_to         ON r_to.oid = c.confrelid <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h4>\u0412 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0439\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u043b\u043e\u043d\u043e\u043a FK \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f NULL<\/h4>\n<p>\u0417\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442, \u0447\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 FK \u0438 \u0431\u0430\u0437\u0430 \u043a\u0430\u043a-\u0442\u043e \u0441\u0430\u043c\u0430 \u0432\u0441\u0451 \u043f\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u0435\u0442. \u0421\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u044f\u0441\u044c \u0432\u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0438\u0445 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f\u043c, \u0442\u0430\u043a\u0438\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438, \u043d\u0435 \u0440\u0435\u0434\u043a\u043e \u043d\u0435 \u043f\u044b\u0442\u0430\u044e\u0442\u0441\u044f \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u0445, \u0430 \u043e\u0442\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043e\u0442 FK \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0411\u0414, \u043f\u043e\u043b\u0430\u0433\u0430\u044f \u0438\u0445 \u0441\u043b\u043e\u0436\u043d\u044b\u043c\u0438 \u0438\u043b\u0438 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u043c\u0438. <\/p>\n<p>\u041f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 FK \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0435\u0433\u043e \u0438\u0437 \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432. \u041e\u0434\u043d\u0430\u043a\u043e \u0435\u0441\u043b\u0438 FK \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043a\u043e\u043b\u043e\u043d\u043e\u043a \u0438 \u0447\u0430\u0441\u0442\u044c \u0438\u0437 \u043d\u0438\u0445 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 NULL, \u0432 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043c\u043e\u0433\u0443\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430.  <\/p>\n<p>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0441 NULL \u0438\u043c\u0435\u0435\u0442 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0437\u043d\u0430\u0442\u044c \u0438 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c [2]. \u0414\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f FK \u0441 \u043a\u043e\u043b\u043e\u043d\u043a\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c NULL, \u0435\u0441\u0442\u044c \u0443\u0442\u043e\u0447\u043d\u044f\u044e\u0449\u0438\u0435 \u043a\u043b\u044e\u0447\u0438 &#8212; <code>MATCH SIMPLE<\/code> (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e) \u0438 <code>MATCH FULL<\/code> (<code>MATCH PARTIAL<\/code> \u0432 PostgreSQL \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d) [3]. <\/p>\n<p><strong>\u0417\u0430\u0434\u0430\u0447\u0430:<\/strong> \u043d\u0430\u0439\u0442\u0438 FK, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0439\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 NULL, \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0442\u0438\u043f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u043d\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0432 <code>MATCH FULL<\/code>.<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u043b\u0443\u0447\u0430\u044f, \u043a\u043e\u0433\u0434\u0430 \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0439\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u043b\u043e\u043d\u043e\u043a FK \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f NULL<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">-- \u0446\u0435\u043b\u0435\u0432\u043e\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 (\u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a)  DROP TABLE IF EXISTS public.fk1002_2 CASCADE; CREATE TABLE public.fk1002_2 (     id    integer NOT NULL,     value varchar(10) NOT NULL,     CONSTRAINT fk1002_2_pk PRIMARY KEY (id, value) );  -- \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a\u0430 INSERT INTO public.fk1002_2 (id, value) VALUES (10, '10'); INSERT INTO public.fk1002_2 (id, value) VALUES (20, '20');  -- \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0435\u0441\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 DROP TABLE IF EXISTS public.fk1002_2_fk; CREATE TABLE public.fk1002_2_fk (     fk1002_2_id integer NOT NULL,     fk1002_2_value varchar(10),     CONSTRAINT fk1002_2_fk_fk1002_2        FOREIGN KEY (fk1002_2_id, fk1002_2_value)          REFERENCES public.fk1002_2 (id, value) );  -- \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 -- \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043f\u043e\u043b\u0435 fk1002_2_value \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c NULL -- \u043e\u0431\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 -- \u0435\u0441\u043b\u0438 \u0431\u044b \u0434\u043b\u044f CONSTRAINT fk1002_2_fk_fk1002_2 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0438 MATCH FULL -- \u0442\u043e\u0433\u0434\u0430 \u0432\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u043d\u0435 \u0431\u044b\u043b\u0430 \u0431\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 INSERT INTO public.fk1002_2_fk (fk1002_2_id, fk1002_2_value) VALUES (20, '20'); INSERT INTO public.fk1002_2_fk (fk1002_2_id, fk1002_2_value) VALUES (30, NULL); <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0434\u043b\u044f \u0441\u043b\u0443\u0447\u0430\u044f, \u043a\u043e\u0433\u0434\u0430 \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0439\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u043b\u043e\u043d\u043e\u043a FK \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f NULL<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">WITH -- \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f FK \u0441 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u043d\u0438\u0445 \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u044b fk_with_attributes AS (         SELECT             c.conname as fk_name,             c.conrelid,             c.confrelid,             c.confmatchtype,             fk_conkey.conkey_order AS att_order,             fk_conkey.conkey_number,             fk_confkey.confkey_number,             rel_att.attname AS rel_att_name,             rel_att.atttypid AS rel_att_type_id,             rel_att.atttypmod AS rel_att_type_mod,             rel_att.attnotnull AS rel_att_notnull,             frel_att.attname AS frel_att_name,             frel_att.atttypid AS frel_att_type_id,             frel_att.atttypmod AS frel_att_type_mod,             frel_att.attnotnull AS frel_att_notnull         FROM pg_catalog.pg_constraint AS c             CROSS JOIN LATERAL UNNEST(c.conkey) WITH ORDINALITY AS fk_conkey(conkey_number, conkey_order)             LEFT JOIN LATERAL UNNEST(c.confkey) WITH ORDINALITY AS fk_confkey(confkey_number, confkey_order)                 ON fk_conkey.conkey_order = fk_confkey.confkey_order             LEFT JOIN pg_catalog.pg_attribute AS rel_att                 ON rel_att.attrelid = c.conrelid AND rel_att.attnum = fk_conkey.conkey_number             LEFT JOIN pg_catalog.pg_attribute AS frel_att                 ON frel_att.attrelid = c.confrelid AND frel_att.attnum = fk_confkey.confkey_number         WHERE c.contype IN ('f')     ) SELECT     c.fk_name,       -- \u043d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f fk     r_from.relname,  -- \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0435\u0441\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435     c.rel_att_names  -- nullable \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u043c\u0441\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 FROM (     -- \u043e\u0442\u0431\u0438\u0440\u0430\u0435\u043c FK, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0441\u0442\u044c \u0440\u0430\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u043a\u043e\u043b\u043e\u043d\u043e\u043a     SELECT         fk_name,         conrelid,         confrelid,         array_agg (rel_att_name order by att_order ) as rel_att_names     FROM fk_with_attributes     WHERE         (rel_att_notnull IS NOT TRUE)         AND confmatchtype NOT IN ('f')     GROUP BY 1, 2, 3 ) AS c     INNER JOIN pg_catalog.pg_class AS r_from         ON r_from.oid = c.conrelid<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h4>FK \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u0438\u043b\u0438 \u0443\u0441\u0442\u0430\u0440\u0435\u043b\u0438<\/h4>\n<p>\u0421\u0438\u0442\u0443\u0430\u0446\u0438\u044f, \u043a\u043e\u0433\u0434\u0430 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0430\u044f\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e FK \u043d\u0430 \u0446\u0435\u043b\u0435\u0432\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0430\u043d\u0430\u043b\u043e\u0433\u043e\u0432 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0434\u0432\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0442\u043e\u0432\u0430\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0430\u043c\u0438 \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0430, \u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0435 \u043f\u043e\u043b\u044f.<\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0439\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0434\u0432\u0430 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043e\u0434\u043d\u0443 \u0446\u0435\u043b\u0435\u0432\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0438\u043c\u0435\u044e\u0442 \u043f\u043e\u043b\u043d\u043e\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432, \u044d\u0442\u043e \u044f\u0432\u043d\u044b\u0439 \u043f\u0440\u0438\u0437\u043d\u0430\u043a \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f FK. \u0415\u0441\u043b\u0438 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432, \u044d\u0442\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0433\u043e \u043e\u0448\u0438\u0431\u043e\u0447\u043d\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f FK \u0438\u043b\u0438 \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0435\u0433\u043e FK. <\/p>\n<p>\u041e\u0433\u043e\u0432\u043e\u0440\u0438\u043c\u0441\u044f \u0441\u0440\u0430\u0437\u0443, \u0447\u0442\u043e \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 FK \u0437\u0430\u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0442\u0441\u044f \u043f\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c, \u0435\u0441\u0442\u044c, \u043e\u0434\u043d\u0430\u043a\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u043e\u043d\u0438 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u0436\u0435, \u0447\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439. <\/p>\n<p><strong>\u0417\u0430\u0434\u0430\u0447\u0430:<\/strong> \u043d\u0430\u0439\u0442\u0438 \u043f\u0430\u0440\u044b FK, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043c\u0435\u044e\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0443\u044e\u0441\u044f \u0438 \u0446\u0435\u043b\u0435\u0432\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0432 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0435\u0439\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0443 \u043d\u0438\u0445 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0442\u0441\u044f.<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f<\/summary>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-372156","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/372156","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=372156"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/372156\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=372156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=372156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=372156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}