{"id":383929,"date":"2024-06-29T05:11:21","date_gmt":"2024-06-29T05:11:21","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=383929"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-06-29T05:11:21","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=383929","title":{"rendered":"<span>\u0427\u0442\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u0432 SQLite 3.35<\/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>\u0412 \u043d\u043e\u0432\u044b\u0445 \u0440\u0435\u043b\u0438\u0437\u0430\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 SQLite \u0447\u0430\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u044e\u0442 \u0434\u0432\u0438\u0436\u043e\u043a \u0442\u0430\u043a \u0438 \u0441\u044f\u043a, \u0430 \u0434\u043b\u044f \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044f \u043d\u0438\u0447\u0435\u0433\u043e \u043e\u0441\u043e\u0431\u043e \u043d\u0435 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f. 2020 \u0433\u043e\u0434 \u0441\u0442\u0430\u043b \u043f\u0440\u0438\u044f\u0442\u043d\u044b\u043c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u2014 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043a\u0443\u0447\u0443 \u043f\u0440\u0438\u044f\u0442\u043d\u044b\u0445 \u0444\u0438\u0447 \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0432\u0440\u043e\u0434\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u044b\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432, <code>UPDATE FROM<\/code> \u0438 \u0432\u0435\u043b\u0438\u043a\u043e\u043b\u0435\u043f\u043d\u043e\u0433\u043e <code>.mode box<\/code> \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438.<\/p>\n<p>\u0415\u0441\u0442\u044c \u0432\u0441\u0435 \u0448\u0430\u043d\u0441\u044b, \u0447\u0442\u043e 2021 \u0433\u043e\u0434 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u044e. \u0412\u043e\u0442 \u0447\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0432 \u0440\u0435\u043b\u0438\u0437\u0435 3.35 (\u0432\u044b\u0448\u0435\u043b 12 \u043c\u0430\u0440\u0442\u0430):<\/p>\n<ol>\n<li>\n<p>\u041c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u203c\ufe0f<\/p>\n<\/li>\n<li>\n<p>\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u2757<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0445 \u0441\u0442\u0440\u043e\u043a \u0434\u043b\u044f <code>DELETE<\/code>, <code>INSERT<\/code> \u0438 <code>UPDATE<\/code> (\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 RETURNING).<\/p>\n<\/li>\n<li>\n<p>\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 CTE.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438:<\/p>\n<h3>\u041c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/h3>\n<p>\u041c\u043d\u043e\u0433\u043e \u043b\u0435\u0442 \u0430\u0432\u0442\u043e\u0440\u043e\u0432 SQLite \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u0443\u043c\u043e\u043b\u044f\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u0440\u043e\u0434\u0435 <code>sqrt()<\/code>, <code>log()<\/code> \u0438 <code>pow()<\/code>. \u041e\u0442\u0432\u0435\u0442 \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u044b\u043b \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439:<\/p>\n<blockquote>\n<p>SQLite \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u00ablite\u00bb. \u041d\u0443\u0436\u043d\u044b \u0432\u0430\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u2014 \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0441\u0430\u043c\u0438.<\/p>\n<\/blockquote>\n<p>\u0412 \u0446\u0435\u043b\u043e\u043c \u043f\u043e\u043d\u044f\u0442\u043d\u0430\u044f \u043f\u043e\u0437\u0438\u0446\u0438\u044f. \u041d\u043e \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u044b\u0439 \u043a\u043e\u0440\u0435\u043d\u044c? \u0418 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u043f\u0440\u043e\u0447\u0443\u044e \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u0443\u044e SQL-\u043c\u0430\u0433\u0438\u044e? \u0421\u0435\u0440\u044c\u0435\u0437\u043d\u043e?<\/p>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0434\u0435\u043b\u043e \u0432 \u0434\u0440\u0443\u0433\u043e\u043c, \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 SQLite \u0434\u0435\u043b\u0430\u044e\u0442 \u0442\u0435 \u0444\u0438\u0447\u0438, \u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0433\u043e\u0442\u043e\u0432\u044b \u043f\u043b\u0430\u0442\u0438\u0442\u044c \u043a\u0440\u0443\u043f\u043d\u044b\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u044b. \u0422\u0430\u043a \u0438\u043b\u0438 \u0438\u043d\u0430\u0447\u0435, \u0441\u043f\u0443\u0441\u0442\u044f 20 \u043b\u0435\u0442 \u0443 \u043d\u0430\u0441 \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438!<\/p>\n<p>\u0412\u043e\u0442 \u043f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a:<\/p>\n<pre><code>acos(X) acosh(X) asin(X) asinh(X) atan(X) atan2(X,Y) ceil(X) ceiling(X) cos(X) cosh(X) degrees(X) exp(X) floor(X) ln(X) log(B,X) log(X) log10(X) log2(X) mod(X,Y) pi() pow(X,Y) power(X,Y) radians(X) sin(X) sinh(X) sqrt(X) tan(X) tanh(X) trunc(X) <\/code><\/pre>\n<h3>\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432<\/h3>\n<p>\u041d\u0430\u0432\u0435\u0440\u043d\u043e, \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u0438 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0441\u0442\u0440\u0430\u0434\u0430\u043d\u0438\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432. \u0420\u0430\u0437\u0434\u0440\u0430\u0436\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0433\u043e\u0434\u043d\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435, \u0430 \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f. \u0425\u043e\u0447\u0435\u0448\u044c \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u2014 \u0434\u0435\u043b\u0430\u0439 \u043a\u043e\u043f\u0438\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0431\u0435\u0437 \u043d\u0435\u0433\u043e, \u0430 \u0441\u0442\u0430\u0440\u0443\u044e \u0443\u0434\u0430\u043b\u044f\u0439.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u044d\u0442\u0430 \u0431\u043e\u043b\u044c \u0442\u043e\u0436\u0435 \u0443\u0439\u0434\u0435\u0442! <code>ALTER TABLE DROP COLUMN<\/code>, \u043a\u0430\u043a \u0434\u043e\u043b\u0433\u043e \u043c\u044b \u0442\u0435\u0431\u044f \u0436\u0434\u0430\u043b\u0438.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0441\u0442\u043e\u043b\u0431\u0435\u0446, SQLite \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u2014 \u0442\u0430\u043a \u0447\u0442\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043d\u0435\u0431\u044b\u0441\u0442\u0440\u0430\u044f. \u041d\u043e \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043f\u0440\u0438\u044f\u0442\u043d\u043e.<\/p>\n<h3>RETURNING<\/h3>\n<p>\u0418\u0437 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 <code>DELETE<\/code>, <code>INSERT<\/code> \u0438 <code>UPDATE<\/code> \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u0447\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d\u0438 \u0443\u0434\u0430\u043b\u0438\u043b\u0438, \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0438\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043d\u043e\u0432\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438:<\/p>\n<pre><code class=\"sql\">create table users (   id integer primary key,   first_name text,   last_name text );  insert into users (first_name, last_name) values ('\u041d\u0438\u043d\u0430', '\u0416\u0443\u043a\u043e\u0432\u0430') returning id; <\/code><\/pre>\n<p>\u0418\u043b\u0438 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0442\u043e\u0432\u0430\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u043e\u0432\u044b\u0441\u0438\u043b\u0438 \u0446\u0435\u043d\u0443:<\/p>\n<pre><code class=\"sql\">update products set price = price * 1.10 where price &lt;= 99.99 returning name, price as new_price; <\/code><\/pre>\n<h3>\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 CTE<\/h3>\n<p>CTE, \u0438\u043b\u0438 Common Table Expression \u2014 \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u043a\u043e\u0440\u043e\u0447\u0435 \u0438 \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u0435\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0433\u043e\u0440\u043e\u0434\u043e\u0432, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u0442\u043e\u043b\u0435\u0442\u0438\u0438:<\/p>\n<pre><code>create table city(   city text,   timezone text,   geo_lat real,   geo_lon real,   population integer,   foundation_year integer );  -- insert data ...  with history as (   select     city,     (foundation_year\/100)+1 as century   from city ) select   century || '-\u0439 \u0432\u0435\u043a' as dates,   count(*) as city_count from history group by century order by century desc; <\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435 CTE \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437, SQLite \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0435\u0433\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442. \u0414\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0431\u044b\u0441\u0442\u0440\u043e.<\/p>\n<p>\u0421 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u043c CTE SQLite \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u043e\u0434\u0438\u043d \u0440\u0430\u0437, \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c (\u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430):<\/p>\n<pre><code>with history as materialized (   select ... ) select ... from history where ... except select ... from history where ... ; <\/code><\/pre>\n<hr\/>\n<p>\u0418 \u0432\u0441\u0435 \u044d\u0442\u043e \u0432 \u043e\u0434\u043d\u043e\u043c \u0440\u0435\u043b\u0438\u0437\u0435! \u041d\u0435\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u30c4<\/p>\n<p><em>\u0415\u0441\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c SQLite \u0432 \u043f\u043e\u0432\u0441\u0435\u0434\u043d\u0435\u0432\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445 \u2014 \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0439\u0442\u0435\u0441\u044c \u043d\u0430 \u043a\u0430\u043d\u0430\u043b <\/em><a href=\"https:\/\/t.me\/sqliter\" rel=\"noopener noreferrer nofollow\"><em>@sqliter<\/em><\/a><\/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\/545310\/\"> https:\/\/habr.com\/ru\/articles\/545310\/<\/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>\u0412 \u043d\u043e\u0432\u044b\u0445 \u0440\u0435\u043b\u0438\u0437\u0430\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 SQLite \u0447\u0430\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u044e\u0442 \u0434\u0432\u0438\u0436\u043e\u043a \u0442\u0430\u043a \u0438 \u0441\u044f\u043a, \u0430 \u0434\u043b\u044f \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044f \u043d\u0438\u0447\u0435\u0433\u043e \u043e\u0441\u043e\u0431\u043e \u043d\u0435 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f. 2020 \u0433\u043e\u0434 \u0441\u0442\u0430\u043b \u043f\u0440\u0438\u044f\u0442\u043d\u044b\u043c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u2014 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043a\u0443\u0447\u0443 \u043f\u0440\u0438\u044f\u0442\u043d\u044b\u0445 \u0444\u0438\u0447 \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0432\u0440\u043e\u0434\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u044b\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432, <code>UPDATE FROM<\/code> \u0438 \u0432\u0435\u043b\u0438\u043a\u043e\u043b\u0435\u043f\u043d\u043e\u0433\u043e <code>.mode box<\/code> \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438.<\/p>\n<p>\u0415\u0441\u0442\u044c \u0432\u0441\u0435 \u0448\u0430\u043d\u0441\u044b, \u0447\u0442\u043e 2021 \u0433\u043e\u0434 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u044e. \u0412\u043e\u0442 \u0447\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0432 \u0440\u0435\u043b\u0438\u0437\u0435 3.35 (\u0432\u044b\u0448\u0435\u043b 12 \u043c\u0430\u0440\u0442\u0430):<\/p>\n<ol>\n<li>\n<p>\u041c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u203c\ufe0f<\/p>\n<\/li>\n<li>\n<p>\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u2757<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0445 \u0441\u0442\u0440\u043e\u043a \u0434\u043b\u044f <code>DELETE<\/code>, <code>INSERT<\/code> \u0438 <code>UPDATE<\/code> (\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 RETURNING).<\/p>\n<\/li>\n<li>\n<p>\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 CTE.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438:<\/p>\n<h3>\u041c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/h3>\n<p>\u041c\u043d\u043e\u0433\u043e \u043b\u0435\u0442 \u0430\u0432\u0442\u043e\u0440\u043e\u0432 SQLite \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u0443\u043c\u043e\u043b\u044f\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u0440\u043e\u0434\u0435 <code>sqrt()<\/code>, <code>log()<\/code> \u0438 <code>pow()<\/code>. \u041e\u0442\u0432\u0435\u0442 \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u044b\u043b \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439:<\/p>\n<blockquote>\n<p>SQLite \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u00ablite\u00bb. \u041d\u0443\u0436\u043d\u044b \u0432\u0430\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u2014 \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0441\u0430\u043c\u0438.<\/p>\n<\/blockquote>\n<p>\u0412 \u0446\u0435\u043b\u043e\u043c \u043f\u043e\u043d\u044f\u0442\u043d\u0430\u044f \u043f\u043e\u0437\u0438\u0446\u0438\u044f. \u041d\u043e \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u044b\u0439 \u043a\u043e\u0440\u0435\u043d\u044c? \u0418 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u043f\u0440\u043e\u0447\u0443\u044e \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u0443\u044e SQL-\u043c\u0430\u0433\u0438\u044e? \u0421\u0435\u0440\u044c\u0435\u0437\u043d\u043e?<\/p>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0434\u0435\u043b\u043e \u0432 \u0434\u0440\u0443\u0433\u043e\u043c, \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 SQLite \u0434\u0435\u043b\u0430\u044e\u0442 \u0442\u0435 \u0444\u0438\u0447\u0438, \u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0433\u043e\u0442\u043e\u0432\u044b \u043f\u043b\u0430\u0442\u0438\u0442\u044c \u043a\u0440\u0443\u043f\u043d\u044b\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u044b. \u0422\u0430\u043a \u0438\u043b\u0438 \u0438\u043d\u0430\u0447\u0435, \u0441\u043f\u0443\u0441\u0442\u044f 20 \u043b\u0435\u0442 \u0443 \u043d\u0430\u0441 \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438!<\/p>\n<p>\u0412\u043e\u0442 \u043f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a:<\/p>\n<pre><code>acos(X) acosh(X) asin(X) asinh(X) atan(X) atan2(X,Y) ceil(X) ceiling(X) cos(X) cosh(X) degrees(X) exp(X) floor(X) ln(X) log(B,X) log(X) log10(X) log2(X) mod(X,Y) pi() pow(X,Y) power(X,Y) radians(X) sin(X) sinh(X) sqrt(X) tan(X) tanh(X) trunc(X) <\/code><\/pre>\n<h3>\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432<\/h3>\n<p>\u041d\u0430\u0432\u0435\u0440\u043d\u043e, \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u0438 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0441\u0442\u0440\u0430\u0434\u0430\u043d\u0438\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432. \u0420\u0430\u0437\u0434\u0440\u0430\u0436\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0433\u043e\u0434\u043d\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435, \u0430 \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f. \u0425\u043e\u0447\u0435\u0448\u044c \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u2014 \u0434\u0435\u043b\u0430\u0439 \u043a\u043e\u043f\u0438\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0431\u0435\u0437 \u043d\u0435\u0433\u043e, \u0430 \u0441\u0442\u0430\u0440\u0443\u044e \u0443\u0434\u0430\u043b\u044f\u0439.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u044d\u0442\u0430 \u0431\u043e\u043b\u044c \u0442\u043e\u0436\u0435 \u0443\u0439\u0434\u0435\u0442! <code>ALTER TABLE DROP COLUMN<\/code>, \u043a\u0430\u043a \u0434\u043e\u043b\u0433\u043e \u043c\u044b \u0442\u0435\u0431\u044f \u0436\u0434\u0430\u043b\u0438.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0441\u0442\u043e\u043b\u0431\u0435\u0446, SQLite \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u2014 \u0442\u0430\u043a \u0447\u0442\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043d\u0435\u0431\u044b\u0441\u0442\u0440\u0430\u044f. \u041d\u043e \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043f\u0440\u0438\u044f\u0442\u043d\u043e.<\/p>\n<h3>RETURNING<\/h3>\n<p>\u0418\u0437 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 <code>DELETE<\/code>, <code>INSERT<\/code> \u0438 <code>UPDATE<\/code> \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u0447\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d\u0438 \u0443\u0434\u0430\u043b\u0438\u043b\u0438, \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0438\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043d\u043e\u0432\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438:<\/p>\n<pre><code class=\"sql\">create table users (   id integer primary key,   first_name text,   last_name text );  insert into users (first_name, last_name) values ('\u041d\u0438\u043d\u0430', '\u0416\u0443\u043a\u043e\u0432\u0430') returning id; <\/code><\/pre>\n<p>\u0418\u043b\u0438 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0442\u043e\u0432\u0430\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u043e\u0432\u044b\u0441\u0438\u043b\u0438 \u0446\u0435\u043d\u0443:<\/p>\n<pre><code class=\"sql\">update products set price = price * 1.10 where price &lt;= 99.99 returning name, price as new_price; <\/code><\/pre>\n<h3>\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 CTE<\/h3>\n<p>CTE, \u0438\u043b\u0438 Common Table Expression \u2014 \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u043a\u043e\u0440\u043e\u0447\u0435 \u0438 \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u0435\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0433\u043e\u0440\u043e\u0434\u043e\u0432, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u0442\u043e\u043b\u0435\u0442\u0438\u0438:<\/p>\n<pre><code>create table city(   city text,   timezone text,   geo_lat real,   geo_lon real,   population integer,   foundation_year integer );  -- insert data ...  with history as (   select     city,     (foundation_year\/100)+1 as century   from city ) select   century || '-\u0439 \u0432\u0435\u043a' as dates,   count(*) as city_count from history group by century order by century desc; <\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435 CTE \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437, SQLite \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0435\u0433\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442. \u0414\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0431\u044b\u0441\u0442\u0440\u043e.<\/p>\n<p>\u0421 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u043c CTE SQLite \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u043e\u0434\u0438\u043d \u0440\u0430\u0437, \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c (\u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430):<\/p>\n<pre><code>with history as materialized (   select ... ) select ... from history where ... except select ... from history where ... ; <\/code><\/pre>\n<hr\/>\n<p>\u0418 \u0432\u0441\u0435 \u044d\u0442\u043e \u0432 \u043e\u0434\u043d\u043e\u043c \u0440\u0435\u043b\u0438\u0437\u0435! \u041d\u0435\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u30c4<\/p>\n<p><em>\u0415\u0441\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c SQLite \u0432 \u043f\u043e\u0432\u0441\u0435\u0434\u043d\u0435\u0432\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445 \u2014 \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0439\u0442\u0435\u0441\u044c \u043d\u0430 \u043a\u0430\u043d\u0430\u043b <\/em><a href=\"https:\/\/t.me\/sqliter\" rel=\"noopener noreferrer nofollow\"><em>@sqliter<\/em><\/a><\/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\/545310\/\"> https:\/\/habr.com\/ru\/articles\/545310\/<\/a><br \/><\/br><\/br><\/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-383929","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/383929","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=383929"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/383929\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=383929"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=383929"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=383929"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}