{"id":414274,"date":"2024-06-29T23:39:48","date_gmt":"2024-06-29T23:39:48","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=414274"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-06-29T23:39:48","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=414274","title":{"rendered":"<span>\u041a\u0430\u043a \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0430\u0431\u0440\u0438\u043a \u0441\u0442\u0440\u043e\u043a \u0432 psycopg<\/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-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/690582\/\"><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/h9\/ac\/aq\/h9acaqpmnzdtbwulzqgzmyk99fa.png\" data-src=\"https:\/\/habrastorage.org\/webt\/h9\/ac\/aq\/h9acaqpmnzdtbwulzqgzmyk99fa.png\"\/><\/div>\n<p><\/a><br \/>  <a href=\"https:\/\/www.psycopg.org\/psycopg3\/docs\/\"><i>psycopg<\/i><\/a> \u2014 \u044d\u0442\u043e \u0430\u0434\u0430\u043f\u0442\u0435\u0440 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 PostgreSQL \u0434\u043b\u044f Python, \u0442\u043e \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0435\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0442\u0438\u043f\u043e\u0432 \u043f\u0440\u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 PostgreSQL \u0438 Python. \u0418 \u0445\u043e\u0442\u044f \u044d\u0442\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043a \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u043c \u0442\u0438\u043f\u0430\u043c, <i>psycopg<\/i> \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/www.psycopg.org\/psycopg3\/docs\/advanced\/rows.html\">\u0444\u0430\u0431\u0440\u0438\u043a \u0441\u0442\u0440\u043e\u043a<\/a>.<a name=\"habracut\"><\/a><\/p>\n<p>  \u042d\u0442\u0438 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043e\u0431\u044b\u0447\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0432 \u0432\u0438\u0434\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 Python, \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0445 \u0441 \u043e\u0434\u043d\u043e\u0439 \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u0441\u0432\u044f\u0437\u0435\u0439 (\u043e\u0431\u044b\u0447\u043d\u043e \u0442\u0430\u0431\u043b\u0438\u0446) \u0432 PostgreSQL. \u0418\u043c\u0435\u043d\u043d\u043e \u0437\u0434\u0435\u0441\u044c \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u0432 \u0438\u0433\u0440\u0443 \u0432\u0441\u0442\u0443\u043f\u0430\u0435\u0442 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Object%E2%80%93relational_mapping\">ORM<\/a> (\u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e-\u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435), \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044f \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u0441\u043b\u043e\u0439 \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0432 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u043c\u043e\u0434\u0435\u043b\u0435\u0439.<\/p>\n<p>  \u0412 <i>psycopg 3<\/i> \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0441\u0442\u0440\u043e\u043a \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044e\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0439, \u043d\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0431\u0435\u0437 \u043f\u0440\u0438\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c, \u043a\u0430\u043a \u044d\u0442\u043e\u0442 \u043b\u0435\u0433\u043a\u043e\u0432\u0435\u0441\u043d\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0431\u043e\u043b\u0435\u0435 \u043d\u0430\u0434\u0451\u0436\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0437\u0430 \u0441\u0447\u0451\u0442 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<h2><font color=\"#3AC1EF\">\u258d \u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0444\u0430\u0431\u0440\u0438\u043a\u0430 \u0441\u0442\u0440\u043e\u043a?<\/font><\/h2>\n<p>  \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043e \u043f\u043e\u0433\u043e\u0434\u0435, \u0441\u043e\u0431\u0438\u0440\u0430\u044f \u043e\u0442\u0447\u0451\u0442\u044b \u043f\u043e \u0434\u0430\u0442\u0430\u043c \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0433\u043e\u0440\u043e\u0434\u043e\u0432 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>weather<\/code>:<\/p>\n<pre><code class=\"python\">CREATE TABLE weather (     city            varchar(80),     temp_lo         int,     temp_hi         int,     prcp            real,     date            date );<\/code><\/pre>\n<p>  \u041f\u0440\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0447\u0435\u0440\u0435\u0437 <i>psycopg<\/i> \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0432\u0438\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043a\u043e\u0440\u0442\u0435\u0436\u0430, \u0433\u0434\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0442\u0438\u043f Python, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0442\u0438\u043f\u0443 PostgreSQL:<\/p>\n<pre><code class=\"python\">>>> with psycopg.connect() as conn: ...     print(conn.execute(\"SELECT * FROM weather\").fetchone()) ('San Francisco', 46, 50, 0.25, datetime.date(1994, 11, 27))<\/code><\/pre>\n<p>  \u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0434\u0440\u0443\u0433\u043e\u0435 \u2014 \u044d\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0441\u0442\u0440\u043e\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code><a href=\"https:\/\/www.psycopg.org\/psycopg3\/docs\/api\/rows.html#psycopg.rows.dict_row\">dict_row<\/a><\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u0433\u0434\u0435 \u0438\u043c\u0435\u043d\u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438:<\/p>\n<pre><code class=\"python\">>>> with psycopg.connect() as conn, conn.cursor(row_factory=psycopg.rows.dict_row) as cur: ...     print(cur.execute(\"SELECT * FROM weather\").fetchone()) {'city': 'San Francisco', 'temp_lo': 46, 'temp_hi': 50, 'prcp': 0.25, 'date': datetime.date(1994, 11, 27)}<\/code><\/pre>\n<p>  \u0424\u0430\u0431\u0440\u0438\u043a\u0430 \u0441\u0442\u0440\u043e\u043a \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u043f\u0440\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u0443\u0440\u0441\u043e\u0440\u0430, \u0438 \u0441\u0442\u0440\u043e\u043a\u0430, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0430\u044f <code><a href=\"https:\/\/www.psycopg.org\/psycopg3\/docs\/api\/cursors.html#psycopg.Cursor.fetchone\">fetchone()<\/a><\/code>, \u043d\u0430 \u0434\u0435\u043b\u0435 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u043e\u0432\u0430\u0440\u0451\u043c.<\/p>\n<p>  \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043a\u043e\u0435-\u0447\u0442\u043e \u043f\u043e\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0435. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 Python \u0435\u0441\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c:<\/p>\n<pre><code class=\"python\">from dataclasses import dataclass from datetime import date  @dataclass class Weather:     city: str     temperature: tuple[int, int]     precipitation: float     date: date<\/code><\/pre>\n<p>  \u0426\u0435\u043b\u044c\u044e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u043a\u043b\u0430\u0441\u0441\u0430 <code>Weather<\/code> \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432\u0440\u043e\u0434\u0435 <code>SELECT * FROM weather<\/code>. \u0417\u0434\u0435\u0441\u044c \u043d\u0430\u043c \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0443\u0436\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0441\u0442\u0440\u043e\u043a.<\/p>\n<p>  \u0424\u0430\u0431\u0440\u0438\u043a\u0430 \u0441\u0442\u0440\u043e\u043a \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0449\u0443\u044e \u0441\u044b\u0440\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 Python (\u043a\u043e\u0442\u043e\u0440\u044b\u0435 <i>psycopg<\/i> \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u043b\u0430 \u0438\u0437 SQL \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439) \u0432 \u043d\u0435\u043a\u0438\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0442\u0438\u043f \u2014 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 <code>Weather<\/code>. \u041d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u0434\u043e\u0431\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">def weather_from_row(city, temp_lo, temp_hi, prcp, date):     return Weather(         city=city, temperature=(temp_lo, temp_hi), precipitation=prcp, date=date     )<\/code><\/pre>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 psycopg \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0451\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u0445 \u0432 \u043d\u0430\u0431\u043e\u0440\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 SQL \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439. \u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0444\u0430\u0431\u0440\u0438\u043a\u0430 \u0441\u0442\u0440\u043e\u043a \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 <a href=\"https:\/\/www.psycopg.org\/psycopg3\/docs\/api\/cursors.html\">\u043a\u0443\u0440\u0441\u043e\u0440<\/a>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0434\u043b\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u0432 \u0444\u0430\u0431\u0440\u0438\u043a\u0443:<\/p>\n<pre><code class=\"python\">def weather_row_factory(cursor):     # \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432.     columns = [column.name for column in cursor.description]      def make_row(values):         # \u0421\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u043c\u0435\u043d\u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438.         row = dict(zip(columns, values))         return weather_from_row(**row)      return make_row<\/code><\/pre>\n<p>  \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u0430\u0447\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u0435\u0441\u043b\u0438 \u044d\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u0443\u0434\u0443\u0442 \u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f <a href=\"https:\/\/docs.python.org\/3\/library\/functions.html#classmethod\">\u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0441\u0430<\/a> <code>Weather<\/code>, \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0448\u0435:<\/p>\n<pre><code class=\"python\">@dataclass class Weather:     city: str     ...      @classmethod     def from_row(cls, *, city, temp_lo, temp_hi, prcp, date):         return cls(             city=city, temperature=(temp_lo, temp_hi), precipitation=prcp, date=date         )      @classmethod     def row_factory(cls, cursor):         columns = [column.name for column in cursor.description]          def make_row(values):             row = dict(zip(columns, values))             return cls.from_row(**row)          return make_row<\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u0432\u0441\u0451 \u043d\u0430 \u0441\u0432\u043e\u0438\u0445 \u043c\u0435\u0441\u0442\u0430\u0445, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043e\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442:<\/p>\n<pre><code class=\"python\">>>> with psycopg.connect() as conn: ...     with conn.cursor(row_factory=Weather.row_factory) as cur: ...         cur.execute(\"SELECT * FROM weather\") ...         row = cur.fetchone() >>> print(row) Weather(city='San Francisco', temperature=(46, 50), precipitation=0.25, date=datetime.date(1994, 11, 27))<\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>row<\/code> \u2014 \u044d\u0442\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <code>Weather<\/code>, \u0437\u043d\u0430\u0447\u0438\u0442, \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0435\u0439 \u043e\u043f\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u0435\u0451 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c:<\/p>\n<pre><code class=\"python\">>>> import statictics >>> statictics.mean(row.temperature) 48<\/code><\/pre>\n<p>  <\/p>\n<h2><font color=\"#3AC1EF\">\u258d \u041f\u043e\u0447\u0435\u043c\u0443 \u044d\u0442\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0435\u0435?<\/font><\/h2>\n<p>  \u0412 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438\u043b\u0438 \u0432\u0432\u043e\u0434\u0430-\u0432\u044b\u0432\u043e\u0434\u0430 \u0432 \u043e\u0431\u0449\u0435\u043c, \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u0433\u0440\u0430\u043d\u0438\u0446\u0435 \u043a\u043e\u0434 \u2014 \u0432 \u043c\u0435\u0441\u0442\u0435, \u0433\u0434\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0436\u0434\u0443 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u043c\u0438 \u0442\u0438\u043f\u043e\u0432 \u2014 \u043e\u0431\u044b\u0447\u043d\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u00ab\u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c\u00bb \u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043e\u0441\u043e\u0431\u043e\u0433\u043e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u043f\u0440\u0438 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438\/\u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438.<\/p>\n<p>  \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438\u0437 <i>psycopg<\/i> \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u0444\u0430\u0431\u0440\u0438\u043a \u0441\u0442\u0440\u043e\u043a, \u043a\u0430\u043a \u044d\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0432\u044b\u0448\u0435, \u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u00ab\u0441\u044b\u0440\u044b\u0445\u00bb \u0442\u0438\u043f\u043e\u0432 Python \u0432 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 \u0440\u0430\u043d\u043d\u0435\u0439 \u0441\u0442\u0430\u0434\u0438\u0438. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432\u0440\u0435\u043c\u044f, \u043f\u0440\u043e\u0432\u0435\u0434\u0451\u043d\u043d\u043e\u0435 \u043d\u0430 \u044d\u0442\u043e\u0439 \u0433\u0440\u0430\u043d\u0438\u0446\u0435 \u0432\u0432\u043e\u0434\u0430-\u0432\u044b\u0432\u043e\u0434\u0430, \u0441\u043e\u043a\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f. \u041a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441 \u043e\u0441\u043e\u0431\u043e\u0439 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0435 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0441\u0442\u0440\u043e\u043a, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u0442\u0430\u0440\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0445 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0422\u043e\u0433\u0434\u0430 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u0434\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u043d\u0435 \u043e\u0437\u0430\u0434\u0430\u0447\u0438\u0432\u0430\u044f\u0441\u044c \u0442\u0438\u043f\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0449\u0438\u0445 \u0438\u0437 \u0411\u0414. \u0412 \u044d\u0442\u043e\u043c \u0442\u0430\u043a\u0436\u0435 \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 ORM.<\/p>\n<p>  \u0415\u0449\u0451 \u043e\u0434\u043d\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0441\u043e\u0432\u043c\u0435\u0449\u0435\u043d\u0438\u0438 \u0444\u0430\u0431\u0440\u0438\u043a \u0441\u0442\u0440\u043e\u043a \u0441\u043e <a href=\"https:\/\/docs.python.org\/3\/library\/typing.html\">\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u0435\u0439<\/a> Python. \u0421\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u044f \u0441 \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u0438\u043f\u043e\u0432 \u0432\u0440\u043e\u0434\u0435 <a href=\"https:\/\/mypy.readthedocs.io\/\">mypy<\/a> \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438, \u043d\u0435 \u0432\u043b\u0438\u044f\u044f \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432 \u0441\u0440\u0435\u0434\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u041e\u0434\u043d\u0430\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u043d\u0430 \u0433\u0440\u0430\u043d\u0438\u0446\u0435 \u0432\u0432\u043e\u0434\u0430-\u0432\u044b\u0432\u043e\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442 \u00ab\u0441\u043b\u0430\u0431\u0443\u044e\u00bb \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u044e (\u0442\u043e \u0435\u0441\u0442\u044c \u0442\u0438\u043f\u044b <code>str<\/code> \u0438\u043b\u0438 <code>dict<\/code> \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u043f\u043e\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>Weather<\/code>, \u0441\u0447\u0438\u0442\u0430\u044e\u0449\u0435\u043c\u0443\u0441\u044f \u00ab\u0441\u0442\u0440\u043e\u0433\u0438\u043c\u00bb \u0442\u0438\u043f\u043e\u043c). \u0412 \u044d\u0442\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0441\u0442\u0440\u043e\u043a, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u0440\u0438\u0432\u043d\u0435\u0441\u0443\u0442 \u0441\u0442\u0440\u043e\u0433\u0443\u044e \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u044e \u043d\u0430 \u0433\u0440\u0430\u043d\u0438\u0446\u0443 \u0432\u0432\u043e\u0434\u0430-\u0432\u044b\u0432\u043e\u0434\u0430. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0438\u043f\u044b \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0441\u043e \u0441\u0442\u0440\u043e\u0433\u0438\u043c\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0432\u0440\u043e\u0434\u0435 <a href=\"https:\/\/pydantic-docs.helpmanual.io\/\">pydantic<\/a>).<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043d\u0435\u0433\u043e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0442\u0438\u043f\u043e\u0432:<\/p>\n<pre><code class=\"python\">from typing import Any, Sequence  @dataclass class Weather:     city: str     ...      @classmethod     def from_row(cls, *, city: str, temp_lo: int, temp_hi: int, prcp: float, date: date) -> Weather:         return cls(             city=city, temperature=(temp_lo, temp_hi), precipitation=prcp, date=date         )      @classmethod     def row_factory(cls, cursor: Cursor[Any]) -> Callable[[Sequence[Any]], Weather]:         columns = [column.name for column in cursor.description]          def make_row(values: Sequence[Any]) -> Weather:             row = dict(zip(columns, values))             return cls.from_row(**row)          return make_row<\/code><\/pre>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0442\u0438\u043f\u043e\u0432:<\/p>\n<pre><code class=\"python\">def get_weather_reports(conn: Connection[Any]) -> list[Weather]:     with conn.cursor(row_factory=Weather.row_factory) as cur:         cur.execute(\"SELECT * FROM weather\")         return cur.fetchall()<\/code><\/pre>\n<p>  \u041f\u0440\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435 \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0441\u0442\u0440\u043e\u043a \u0432 \u043a\u0443\u0440\u0441\u043e\u0440, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0432\u044b\u0437\u043e\u0432\u043e\u043c <code><a href=\"https:\/\/www.psycopg.org\/psycopg3\/docs\/api\/cursors.html#psycopg.Cursor.fetchall\">fetchall()<\/a><\/code>, \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u043e \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u0442\u0438\u043f\u043e\u043c \u0441\u0442\u0440\u043e\u043a\u0438. \u041a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u0437\u0434\u0435\u0441\u044c \u043a\u0443\u0440\u0441\u043e\u0440 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0444\u0430\u0431\u0440\u0438\u043a\u0443, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u0442\u0438\u043f\u043e\u043c <code>Weather<\/code>, \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0447\u0435\u0433\u043e <code>fetchall()<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>list[Weather]<\/code>, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043e \u0432 <code>get_weather_reports()<\/code> (\u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0435\u043d\u043e \u043c\u043e\u0434\u0443\u043b\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u0438\u043f\u043e\u0432 \u0432\u0440\u043e\u0434\u0435 mypy). \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0435\u0435, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0442 \u0438\u0437 \u0411\u0414 \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u0433\u0438\u0445 \u0442\u0438\u043f\u043e\u0432 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>Weather<\/code>), \u0430 \u043d\u0435 <code>tuple<\/code> (\u0438\u043b\u0438 <code>dict<\/code>) \u0430\u043d\u043e\u043d\u0438\u043c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 (<code>int<\/code>, <code>date<\/code> \u0438 \u0442.\u0434.).<\/p>\n<p>  \u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \u0442\u0430\u043a\u0436\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u0442\u043e\u0442 \u0444\u0430\u043a\u0442, \u0447\u0442\u043e \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u044d\u0442\u0438 \u0441\u0442\u0440\u043e\u0433\u043e \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0438\u0437\u0431\u0435\u0433\u0430\u044f \u043e\u0448\u0438\u0431\u043e\u043a \u0432 \u0441\u0440\u0435\u0434\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>IndexError<\/code> \u0434\u043b\u044f <code>tuple<\/code> \u0438\u043b\u0438 <code>KeyError<\/code> \u0434\u043b\u044f <code>dict<\/code>), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u0438\u043f\u043e\u0432 \u0432\u044b\u044f\u0432\u0438\u0442\u044c \u043d\u0435\u0441\u043f\u043e\u0441\u043e\u0431\u0435\u043d. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0442\u0438\u043f\u0438\u0447\u043d\u0443\u044e <code>AttributeError<\/code>, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0449\u0443\u044e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0442\u0440\u043e\u0433\u0438\u0445 \u0442\u0438\u043f\u043e\u0432, \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043d\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442. \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u043d\u0438\u0436\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u0443\u044e <code>IndexError<\/code> \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0438\u0442\u044c \u0434\u043e \u0441\u0440\u0435\u0434\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">>>> with conn.cursor() as cur: ...     rows = cur.execute(\"SELECT * FROM weather\").fetchall()  # \u0442\u0438\u043f list[tuple[Any, ...]] >>> rows[0][5] Traceback (most recent call last):   ... IndexError: tuple index out of range<\/code><\/pre>\n<p>  \u0410 \u0432\u043e\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e <code>AttributeError<\/code> \u043c\u043e\u0434\u0443\u043b\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0443\u0436\u0435 \u043e\u0442\u043b\u043e\u0432\u0438\u0442, \u0438 \u0432 \u0441\u0440\u0435\u0434\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u043d\u0430 \u043d\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0435\u0442:<\/p>\n<pre><code class=\"python\">>>> with conn.cursor(row_factory=Weather.row_factory) as cur: ...     rows = cur.execute(\"SELECT * FROM weather\").fetchall() # \u0442\u0438\u043f list[Weather] >>> rows[0].prcp Traceback (most recent call last):   ... AttributeError: 'Weather' object has no attribute 'prcp'<\/code><\/pre>\n<p>  \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0430\u0431\u0440\u0438\u043a \u0441\u0442\u0440\u043e\u043a \u043c\u044b \u043f\u043e\u0432\u044b\u0448\u0430\u0435\u043c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c, \u043d\u043e \u0438 \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437\u0431\u0435\u0433\u0430\u0435\u043c \u043d\u0435\u0443\u043a\u043b\u044e\u0436\u0438\u0445 <code>dict<\/code> \u0438 \u043f\u0440\u043e\u0447\u0435\u0433\u043e.<\/p>\n<h2><font color=\"#3AC1EF\">\u258d \u041a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0438\u0437\u043d\u0443\u0442\u0440\u0438?<\/font><\/h2>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0447\u0430\u0441\u0442\u044c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0430, \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0449\u0430\u044f, \u0447\u0442\u043e \u0442\u0438\u043f\u044b, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0435 \u0432 \u0444\u0430\u0431\u0440\u0438\u043a\u0435 \u0441\u0442\u0440\u043e\u043a, \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0442\u043e\u0434\u044b <code>Cursor<\/code>, \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0439. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0442\u043e\u0433\u0434\u0430 \u0435\u0449\u0451 \u0440\u0430\u0437 \u0432\u043e\u0437\u044c\u043c\u0451\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0437\u043e\u0432\u043e\u0432 <code><a href=\"https:\/\/mypy.readthedocs.io\/en\/stable\/common_issues.html#reveal-type\">reveal_type()<\/a><\/code>, \u043e\u0442\u0440\u0430\u0437\u0438\u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445:<\/p>\n<pre><code class=\"python\">def get_weather_reports(conn: Connection[Any]) -> list[Weather]:     with conn.cursor(row_factory=Weather.row_factory) as cur:         reveal_type(cur)         # note: \u0440\u0430\u0441\u043a\u0440\u044b\u0442 \u0442\u0438\u043f \"psycopg.cursor.Cursor[Weather]\"         cur.execute(\"SELECT * FROM weather\")         rset = cur.fetchall()         reveal_type(rset)         # note: \u0440\u0430\u0441\u043a\u0440\u044b\u0442 \u0442\u0438\u043f \"builtins.list[Weather]\"         return rset<\/code><\/pre>\n<p>  \u0412\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>cur: Cursor[Weather]<\/code> \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u00ab\u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u043c\u00bb \u0442\u0438\u043f\u0435 <code>Weather<\/code>, \u043a\u0430\u043a \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043e \u0432 <code>Weather.row_factory(cursor: Cursor[Any]) -> Callable[[Sequence[Any]], Weather]<\/code> (\u0432\u0430\u0436\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u2014 \u044d\u0442\u043e \u0442\u0438\u043f <code>Weather<\/code>, \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043a\u0430\u043a \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432\u044b\u0437\u043e\u0432\u0430, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0444\u0430\u0431\u0440\u0438\u043a\u043e\u0439 \u0441\u0442\u0440\u043e\u043a). \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c <code>rset: list[Weather]<\/code> \u043d\u0430 \u0434\u0435\u043b\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a\u0430\u043a \u0441\u043f\u0438\u0441\u043e\u043a \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 <code>Weather<\/code>.<\/p>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043c\u044b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 <code>Connection<\/code> \u0432 <i>psycopg<\/i> (\u0432 \u0443\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u043e\u043c \u0432\u0438\u0434\u0435):<\/p>\n<pre><code class=\"python\">Row = TypeVar(\"Row\", covariant=True) RowFactory = Callable[[Sequence[Any]], Row]  # \u0443\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u0430\u044f \u0444\u043e\u0440\u043c\u0430  class Connection:      @overload     def cursor(self) -> Cursor[Tuple[Any, ...]]:         ...      @overload     def cursor(self, *, row_factory: RowFactory[Row]) -> Cursor[Row]:         ...      def cursor(self, *, row_factory: Optional[RowFactory[Any]] = None) -> Cursor[Any]:         # \u0437\u0434\u0435\u0441\u044c \u0438\u0434\u0451\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/code><\/pre>\n<p>  \u041c\u0435\u0442\u043e\u0434 <code><a href=\"https:\/\/www.psycopg.org\/psycopg3\/docs\/api\/connections.html#psycopg.Connection.cursor\">Connection.cursor()<\/a><\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a <a href=\"https:\/\/docs.python.org\/3\/library\/typing.html#typing.overload\">\u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0430<\/a>, \u0437\u0430\u0432\u0438\u0441\u044f \u043e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 <code>row_factory<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044f \u043e\u0431\u044a\u0435\u043a\u0442 <code>Cursor<\/code> \u0441 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043e\u0441\u043e\u0431\u043e\u0433\u043e \u0442\u0438\u043f\u0430 <code>Row<\/code>. \u0418\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u044d\u0442\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0442\u0438\u043f\u0430 <code>Row<\/code> \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0441\u0442\u0440\u043e\u043a \u043a \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e <code>Cursor<\/code>.<\/p>\n<p>  \u0417\u0430\u0442\u0435\u043c \u0442\u0430 \u0436\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0441 \u0442\u0438\u043f\u043e\u043c <code>Row<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f <a href=\"https:\/\/docs.python.org\/3\/library\/typing.html#typing.Generic\">\u043e\u0431\u043e\u0431\u0449\u0451\u043d\u043d\u043e\u0433\u043e<\/a> \u043a\u043b\u0430\u0441\u0441\u0430 <code>Cursor<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u0430\u043c <code>fetch*()<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>Row<\/code> (\u0442\u0430\u043a\u0436\u0435 \u0432 \u0443\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u0435):<\/p>\n<pre><code class=\"python\">class Cursor(Generic[Row]):      def fetchone(self) -> Optional[Row]:         ...      def fetchall(self) -> List[Row]:         ...<\/code><\/pre>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f \u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u0443:<\/p>\n<pre><code class=\"python\">>>> cur = conn.cursor(row_factory=Weather.row_factory) >>> cur.execute(\"SELECT * FROM weather\") >>> rows = cur.fetchall()<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li><code>cur<\/code> \u2014 \u044d\u0442\u043e <code>Cursor[Weather]<\/code>, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 <code>Weather.row_factory<\/code> \u0438\u043c\u0435\u0435\u0442 \u0442\u0438\u043f <code>RowFactory[Weather]<\/code>, \u0430<\/li>\n<li><code>rows<\/code> \u2014 \u044d\u0442\u043e <code>list<\/code> \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 <code>Weather<\/code>, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 <code>cur<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <code>Cursor[Weather<\/code>].<\/li>\n<\/ul>\n<p>  \u0412\u043e\u0442 \u0438 \u0432\u0435\u0441\u044c \u043e\u0431\u0437\u043e\u0440 \u0444\u0430\u0431\u0440\u0438\u043a \u0441\u0442\u0440\u043e\u043a \u0432 <i>psycopg<\/i>. \u0414\u0430\u043b\u0435\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u043a \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043e <a href=\"https:\/\/www.psycopg.org\/psycopg3\/docs\/advanced\/typing.html\">\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u0438<\/a> (\u0433\u0434\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0435\u0442\u0441\u044f, \u043a\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c <code>Cursor<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u0438\u0435\u043c \u0434\u043b\u044f <code>Row<\/code>), \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 <a href=\"https:\/\/www.psycopg.org\/psycopg3\/docs\/advanced\/rows.html\">\u0444\u0430\u0431\u0440\u0438\u043a \u0441\u0442\u0440\u043e\u043a<\/a> \u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435, \u043f\u043e\u0441\u0432\u044f\u0449\u0451\u043d\u043d\u043e\u0439 <a href=\"https:\/\/www.psycopg.org\/psycopg3\/docs\/api\/rows.html\">\u043c\u043e\u0434\u0443\u043b\u044e rows<\/a>, \u0433\u0434\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0444\u0430\u0431\u0440\u0438\u043a \u0441\u0442\u0440\u043e\u043a.<\/p>\n<blockquote><p><b><font color=\"#3AC1EF\"><a href=\"https:\/\/bit.ly\/3KZeaxv\">Telegram-\u043a\u0430\u043d\u0430\u043b<\/a> \u0438 <a href=\"https:\/\/bit.ly\/3qoIOXs\">\u0443\u044e\u0442\u043d\u044b\u0439 \u0447\u0430\u0442<\/a> \u0434\u043b\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432<\/font><\/b><\/p><\/blockquote>\n<p><a href=\"http:\/\/ruvds.com\/ru-rub?utm_source=habr&amp;utm_medium=article&amp;utm_campaign=Bright_Translate&amp;utm_content=kak_povysit_bezopasnost_prilozhenij_s_pomoshhyu_fabrik_strok_v_psycopg\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/sz\/7j\/pf\/sz7jpfj8i1pa6ocj-eia09dev4q.png\" data-src=\"https:\/\/habrastorage.org\/webt\/sz\/7j\/pf\/sz7jpfj8i1pa6ocj-eia09dev4q.png\"\/><\/a><\/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\/690582\/\"> https:\/\/habr.com\/ru\/articles\/690582\/<\/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-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/690582\/\"><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/h9\/ac\/aq\/h9acaqpmnzdtbwulzqgzmyk99fa.png\" data-src=\"https:\/\/habrastorage.org\/webt\/h9\/ac\/aq\/h9acaqpmnzdtbwulzqgzmyk99fa.png\"\/><\/div>\n<p><\/a><br \/>  <a href=\"https:\/\/www.psycopg.org\/psycopg3\/docs\/\"><i>psycopg<\/i><\/a> \u2014 \u044d\u0442\u043e \u0430\u0434\u0430\u043f\u0442\u0435\u0440 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 PostgreSQL \u0434\u043b\u044f Python, \u0442\u043e \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0435\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0442\u0438\u043f\u043e\u0432 \u043f\u0440\u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 PostgreSQL \u0438 Python. \u0418 \u0445\u043e\u0442\u044f \u044d\u0442\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043a \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u043c \u0442\u0438\u043f\u0430\u043c, <i>psycopg<\/i> \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/www.psycopg.org\/psycopg3\/docs\/advanced\/rows.html\">\u0444\u0430\u0431\u0440\u0438\u043a \u0441\u0442\u0440\u043e\u043a<\/a>.<\/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-414274","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/414274","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=414274"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/414274\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=414274"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=414274"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=414274"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}