{"id":277729,"date":"2016-04-06T08:29:02","date_gmt":"2016-04-06T04:29:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=277729"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=277729","title":{"rendered":"\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0442\u0440\u044e\u043a\u0438 PostgreSQL"},"content":{"rendered":"<p>       <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/cdc\/47f\/83c\/cdc47f83c64847e3adda8cece9d9b978.jpg\"\/><\/p>\n<p>  \u0412 \u043c\u0430\u043d\u0443\u0430\u043b\u0435 \u0435\u0441\u0442\u044c \u0432\u0441\u0451. \u041d\u043e \u0447\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u043e\u0441\u043e\u0437\u043d\u0430\u0442\u044c, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0433\u043e\u0434\u044b. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u044b\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c Postrges \u2014 \u044d\u0442\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a \u0434\u0435\u043b\u0430\u044e\u0442 \u043a\u043e\u043b\u043b\u0435\u0433\u0438. \u041d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445. \u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0442\u0435\u043c, \u043a\u0442\u043e \u0445\u043e\u0447\u0435\u0442 \u0433\u043b\u0443\u0431\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 postgres \u0438\u043b\u0438 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043d\u0430 \u044d\u0442\u0443 \u0421\u0423\u0411\u0414. <br \/>  <a name=\"habracut\"><\/a><\/p>\n<h2>\u041f\u0440\u0438\u043c\u0435\u0440 1<\/h2>\n<p>  \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u043d\u0430\u0434\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435\u0442 \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u0435, \u043f\u0440\u0438\u0447\u0435\u043c \u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u0435\u0439 \u043d\u0430 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u043e\u0441\u0442\u044c. <\/p>\n<p>  \u0422\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u043a (\u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 3 \u043f\u043e\u043b\u044f):<\/p>\n<pre><code class=\"sql\">SELECT t1.*  FROM table1 t1     LEFT JOIN table2 t2         ON t1.field1 = t2.field1              AND t1.field2 = t2.field2             AND t1.field3 = t2.field3 WHERE      t2.field1 IS NULL; <\/code><\/pre>\n<p>  \u0421\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u043d\u043e\u0433\u043e\u0441\u043b\u043e\u0432\u043d\u043e, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u043f\u043e\u043b\u0435\u0439.<br \/>  \u0412 \u043f\u043e\u0441\u0433\u0440\u0435\u0441\u0435 \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0438\u043f Record. \u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0435\u0433\u043e \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u0430\u043c\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<\/p>\n<pre><code class=\"sql\">postgres=# SELECT table1 FROM table1;  table1   ---------  (1,2,3)  (2,3,4) <\/code><\/pre>\n<p>  (\u0412\u044b\u0432\u0435\u0434\u0435\u0442 \u0432 \u0441\u043a\u043e\u0431\u043e\u0447\u043a\u0430\u0445)<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438<\/p>\n<pre><code class=\"sql\">SELECT table1.*      FROM table1          LEFT JOIN table2             ON table1 = table2 WHERE      table2 Is NULL; <\/code><\/pre>\n<p>  \u0438\u043b\u0438 \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"sql\">SELECT *  FROM table1  WHERE NOT EXISTS (     SELECT *      FROM table2      WHERE         table2 = table1 ); <\/code><\/pre>\n<h2>\u041f\u0440\u0438\u043c\u0435\u0440 2<\/h2>\n<p>  \u041e\u0447\u0435\u043d\u044c \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430. \u041f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043f\u0438\u0441\u044c\u043c\u043e \u201c\u0412\u0441\u0442\u0430\u0432\u044c, \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u0434\u043b\u044f \u044e\u0437\u0435\u0440\u043e\u0432 100, 110, 153, 100500 \u0442\u0430\u043a\u0438\u0435-\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435\u201d.<br \/>  \u0422.\u0435. \u043d\u0430\u0434\u043e \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a, \u0433\u0434\u0435 id \u0440\u0430\u0437\u043d\u044b\u0435, \u0430 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e\u0435. <br \/>  \u041c\u043e\u0436\u043d\u043e \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u201c\u043f\u043e\u0440\u0442\u044f\u043d\u043a\u0443\u201d:<\/p>\n<pre><code class=\"sql\">INSERT INTO important_user_table (id, date_added, status_id) VALUES (100, '2015-01-01', 3), (110, '2015-01-01', 3), (153, '2015-01-01', 3), (100500, '2015-01-01', 3); <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 id \u043c\u043d\u043e\u0433\u043e, \u0442\u043e \u044d\u0442\u043e \u0441\u043b\u0435\u0433\u043a\u0430 \u043d\u0430\u043f\u0440\u044f\u0433\u0430\u0435\u0442. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0443 \u043c\u0435\u043d\u044f \u0430\u043b\u043b\u0435\u0440\u0433\u0438\u044f \u043d\u0430 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430.<\/p>\n<p>  \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0432 \u043f\u043e\u0441\u0433\u0440\u0435\u0441\u0435 \u0435\u0441\u0442\u044c \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 \u201c\u043c\u0430\u0441\u0441\u0438\u0432\u201d, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f unnest, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0437 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0434\u0435\u043b\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<p>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <\/p>\n<pre><code class=\"sql\">postgres=# select unnest(array[1,2,3]) as id;  id  ----   1   2   3 (3 rows) <\/code><\/pre>\n<p>  \u0422.\u0435. \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u043a<\/p>\n<pre><code class=\"sql\">INSERT INTO important_user_table  (id, date_added_status_id) SELECT      unnest(array[100, 110, 153, 100500]), '2015-01-01', 3; <\/code><\/pre>\n<p>  \u0442.\u0435. \u0441\u043f\u0438\u0441\u043e\u043a id \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u043e\u043f\u0438\u043f\u0430\u0441\u0442\u0438\u043c \u0438\u0437 \u043f\u0438\u0441\u044c\u043c\u0430. \u041e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e.<\/p>\n<p>  \u041a\u0441\u0442\u0430\u0442\u0438, \u0435\u0441\u043b\u0438 \u0436\u0435 \u0432\u0430\u043c \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442 \u043d\u0443\u0436\u0435\u043d \u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u0437 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0442\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0442\u0430\u043a \u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u2014 array(). \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, select array(select id from important_user_table);<\/p>\n<h2>\u041f\u0440\u0438\u043c\u0435\u0440 3<\/h2>\n<p>  \u0414\u043b\u044f \u0441\u0445\u043e\u0436\u0438\u0445 \u0446\u0435\u043b\u0435\u0439 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0442\u0440\u044e\u043a. \u041c\u0430\u043b\u043e \u043a\u0442\u043e \u0437\u043d\u0430\u0435\u0442, \u0447\u0442\u043e \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441   <\/p>\n<pre><code class=\"sql\">VALUES (1, 'one'), (2, 'two'), (3, 'three') <\/code><\/pre>\n<p>  \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 INSERT \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445, \u043d\u043e \u0438 \u0432 SELECT, \u043d\u0430\u0434\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0441\u043a\u043e\u0431\u043e\u0447\u043a\u0438 \u0432\u0437\u044f\u0442\u044c  <\/p>\n<pre><code class=\"sql\">SELECT * FROM (     VALUES (1, 'one'), (2, 'two'), (3, 'three') ) as t (digit_number, string_number);  digit_number | string_number  --------------+---------------             1 | one             2 | two             3 | three (3 rows) <\/code><\/pre>\n<p>  \u041e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u0430\u0440 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439.<\/p>\n<h2>\u041f\u0440\u0438\u043c\u0435\u0440 4<\/h2>\n<p>  \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0447\u0442\u043e-\u0442\u043e \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c, \u043f\u0440\u043e\u0430\u043f\u0434\u0435\u0439\u0442\u0438\u0442\u044c, \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c id \u0437\u0430\u0442\u0440\u043e\u043d\u0443\u0442\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. \u0427\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e, \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b. \u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u0441\u0451 \u044d\u0442\u043e \u0437\u0430\u043f\u0438\u0445\u0430\u0442\u044c \u0432 CTE. <\/p>\n<pre><code class=\"sql\">WITH  updated AS (        UPDATE table1  \tSET x = 5, y = 6 \tWHERE z &gt; 7         RETURNING id ), inserted AS (        INSERT INTO table2         (x, y, z)         VALUES          (5, 7, 10)         RETURNING id ) SELECT id  FROM updated UNION SELECT id  FROM inserted;  <\/code><\/pre>\n<p>  \u041d\u043e \u0431\u0443\u0434\u044c\u0442\u0435 \u043e\u0447\u0435\u043d\u044c \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b. \u0412\u0441\u0435 \u043f\u043e\u0434\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f CTE \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u044e\u0442\u0441\u044f \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u0434\u0440\u0443\u0433 \u0441 \u0434\u0440\u0443\u0433\u043e\u043c, \u0438 \u0438\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u043e\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043e\u0434\u043d\u0443 \u0438 \u0442\u0443 \u0436\u0435 \u0432\u0435\u0440\u0441\u0438\u044e (snapshot), \u0442.\u0435. \u0435\u0441\u043b\u0438 \u0432 \u043e\u0434\u043d\u043e\u043c \u043f\u043e\u0434\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0438 \u0432\u044b \u043f\u0440\u0438\u0431\u0430\u0432\u0438\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u043a \u043f\u043e\u043b\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u0432\u044b\u0447\u043b\u0438, \u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0447\u0442\u043e \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0447\u0442\u043e-\u0442\u043e \u043e\u0434\u043d\u043e \u0438\u0437 \u043d\u0438\u0445. <\/p>\n<h2>\u041f\u0440\u0438\u043c\u0435\u0440 5<\/h2>\n<p>  \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0432 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c stats \u0435\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430 \u043e\u0434\u0438\u043d \u0434\u0435\u043d\u044c:<\/p>\n<pre><code class=\"sql\">postgres=# select * from stats;   added_at  | money   ------------+--------  2016-04-04 | 100.00 (1 row) <\/code><\/pre>\n<p>  \u0410 \u0432\u0430\u043c \u043d\u0430\u0434\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0441\u0442\u0430\u0442\u0443 \u0437\u0430 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u0435\u0440\u0438\u043e\u0434, \u0437\u0430\u043c\u0435\u043d\u0438\u0432 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0443\u043b\u044f\u043c\u0438. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e generate_series<\/p>\n<pre><code class=\"sql\">SELECT gs.added_at, coalesce(stats.money, 0.00) as money FROM     generate_series('2016-04-01'::date, '2016-04-07'::date , interval '1 day') as gs(added_at)      LEFT JOIN stats          ON stats.added_at = gs.added_at;          added_at        | money   ------------------------+--------  2016-04-01 00:00:00+03 |   0.00  2016-04-02 00:00:00+03 |   0.00  2016-04-03 00:00:00+03 |   0.00  2016-04-04 00:00:00+03 | 100.00  2016-04-05 00:00:00+03 |   0.00  2016-04-06 00:00:00+03 |   0.00  2016-04-07 00:00:00+03 |   0.00 (7 rows) <\/code><\/pre>\n<p>  \u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u044d\u0442\u043e\u0442 \u0442\u0440\u044e\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0434\u0430\u0442\u0430\u043c\u0438, \u043d\u043e \u0438 \u0441 \u0447\u0438\u0441\u043b\u0430\u043c\u0438. \u041f\u0440\u0438\u0447\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e generate_series \u0432 \u043e\u0434\u043d\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435:  <\/p>\n<pre><code class=\"sql\">teasernet_maindb=&gt; select  generate_series (1,10), generate_series(1,2);  generate_series | generate_series  -----------------+-----------------                1 |               1                2 |               2                3 |               1                4 |               2                5 |               1                6 |               2                7 |               1                8 |               2                9 |               1               10 |               2 (10 rows) <\/code><\/pre>\n<p>  <\/p>\n<h1>\u041f\u0440\u0438\u043c\u0435\u0440 n+1<\/h1>\n<p>  \u0412\u043e\u043e\u0431\u0449\u0435, \u044f \u043f\u0438\u0448\u0443 \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0430 \u0445\u0430\u0431\u0440, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u043e\u043f\u044b\u0442\u0430 \u0438\u0437 \u043a\u043e\u043c\u0435\u043d\u0442\u043e\u0432 ) <br \/>  \u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u043d\u0430\u043f\u0438\u0448\u0438\u0442\u0435, \u0447\u0442\u043e \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0432 \u043f\u043e\u0432\u0441\u0435\u0434\u043d\u0435\u0432\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u0435. \u0427\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0442\u0430\u043a\u043e\u0435, \u0447\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0434\u043b\u044f \u043b\u044e\u0434\u0435\u0439, \u043f\u0435\u0440\u0435\u0435\u0445\u0430\u0432\u0448\u0438\u0445 \u0441 \u0434\u0440\u0443\u0433\u0438\u0445 \u0421\u0423\u0411\u0414, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 \u0442\u043e\u0433\u043e \u0436\u0435 mysql?               <\/p>\n<div class=\"clear\"><\/div>\n<p> \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:\/\/habrahabr.ru\/post\/280912\/\"> https:\/\/habrahabr.ru\/post\/280912\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/cdc\/47f\/83c\/cdc47f83c64847e3adda8cece9d9b978.jpg\"\/><\/p>\n<p>  \u0412 \u043c\u0430\u043d\u0443\u0430\u043b\u0435 \u0435\u0441\u0442\u044c \u0432\u0441\u0451. \u041d\u043e \u0447\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u043e\u0441\u043e\u0437\u043d\u0430\u0442\u044c, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0433\u043e\u0434\u044b. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u044b\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c Postrges \u2014 \u044d\u0442\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a \u0434\u0435\u043b\u0430\u044e\u0442 \u043a\u043e\u043b\u043b\u0435\u0433\u0438. \u041d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445. \u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0442\u0435\u043c, \u043a\u0442\u043e \u0445\u043e\u0447\u0435\u0442 \u0433\u043b\u0443\u0431\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 postgres \u0438\u043b\u0438 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043d\u0430 \u044d\u0442\u0443 \u0421\u0423\u0411\u0414.   <\/p>\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-277729","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/277729","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=277729"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/277729\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=277729"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=277729"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=277729"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}