<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
  <channel>
    <title>PostgreSQL</title>
    <description>Установка, наладка и работа с PostgreSQL базами</description>
    <pubDate>Mon, 13 Apr 2026 23:30:23 +0000</pubDate>
    <lastBuildDate>Mon, 13 Apr 2026 23:30:23 +0000</lastBuildDate>
    <generator>Форум PHP Программистов | PHP.ru</generator>
    <link>https://php.ru/forum/forums/postgresql.22/</link>
    <atom:link rel="self" type="application/rss+xml" href="https://php.ru/forum/forums/postgresql.22/index.rss"/>
    <item>
      <title>Подсчитать сумму элементов jsonb</title>
      <pubDate>Wed, 22 Jan 2025 23:37:43 +0000</pubDate>
      <link>https://php.ru/forum/threads/podschitat-summu-ehlementov-jsonb.103036/</link>
      <guid>https://php.ru/forum/threads/podschitat-summu-ehlementov-jsonb.103036/</guid>
      <author>invalid@example.com (polin11)</author>
      <dc:creator>polin11</dc:creator>
      <content:encoded><![CDATA[Использую PGSQL.<br />
Есть 2 поля в таблице One(jsonb), Two(jsonb)<br />
<br />
каждое поле всегда состоят из 3 jsonb элементов<br />
<br />


<div class="bbCodeBlock bbCodeCode">
	<div class="type">Код (Text):</div>
	<div class="code"><ol class="text" style="font-family:monospace;"><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">Пример:</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">One: [{'А': 10, 'B': 5},{'C': 6},{'D': 1}]</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">Two: [{'A_1': 'A_2', 'A_3': 'A_4'}, {'B_1': 'B_2'}, {'D_1': 'D_2'}]</div></li>
</ol></div>
</div>Для поля One  нужно посчитать сумму всех элементах во всех 3 jsonb для примера выше<br />
сумма будет 10+5+6+1=22.<br />
<br />
Для поля Two  нужно посчитать количество всех ключей во всех 3 json для примера выше<br />
количество будет 4.<br />
<br />
Написал такой запрос<br />
<br />


<div class="bbCodeBlock bbCodeCode">
	<div class="type">Код (Text):</div>
	<div class="code"><ol class="text" style="font-family:monospace;"><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">select...</div></li>
</ol></div>
</div><a href="https://php.ru/forum/threads/podschitat-summu-ehlementov-jsonb.103036/" class="internalLink">Подсчитать сумму элементов jsonb</a>]]></content:encoded>
    </item>
    <item>
      <title>Проблемы при импорте в postgres</title>
      <pubDate>Fri, 24 May 2024 10:15:13 +0000</pubDate>
      <link>https://php.ru/forum/threads/problemy-pri-importe-v-postgres.102308/</link>
      <guid>https://php.ru/forum/threads/problemy-pri-importe-v-postgres.102308/</guid>
      <author>invalid@example.com (ecocity)</author>
      <dc:creator>ecocity</dc:creator>
      <content:encoded><![CDATA[Импортирую файл в postgres через dbeaver, возникает ошибка SQL Error [22003]: ERROR: integer out of range, пытался менять тип данных на bigint но это не помогает, не понимаю как это преодолеть.]]></content:encoded>
    </item>
    <item>
      <title>PHP + PgSQL, вопрос про организацию работы веб-приложений</title>
      <pubDate>Fri, 02 Feb 2024 06:31:15 +0000</pubDate>
      <link>https://php.ru/forum/threads/php-pgsql-vopros-pro-organizaciju-raboty-veb-prilozhenij.101506/</link>
      <guid>https://php.ru/forum/threads/php-pgsql-vopros-pro-organizaciju-raboty-veb-prilozhenij.101506/</guid>
      <author>invalid@example.com (Afterrburner)</author>
      <dc:creator>Afterrburner</dc:creator>
      <content:encoded><![CDATA[Всем привет,<br />
В нашей компании порядка 2000 пользователей, одновременно работать могут около 200.<br />
Корпоративные веб-приложения работают с БД через Zend, соединение с PgSQL устанавливается при каждом вызове скрипта PHP, под одной и той же учётной записью PgSQL. Постоянное соединение с PostgreSQL не используется.<br />
Так же активно используется AJAX, таким образом, одновременно может &quot;висеть&quot; до 200 активных сессий в БД.<br />
Всё вроде бы нормально, но есть какие-то необъяснимые пока &quot;лаги&quot; в виде 5...<br />
<br />
<a href="https://php.ru/forum/threads/php-pgsql-vopros-pro-organizaciju-raboty-veb-prilozhenij.101506/" class="internalLink">PHP + PgSQL, вопрос про организацию работы веб-приложений</a>]]></content:encoded>
      <slash:comments>3</slash:comments>
    </item>
    <item>
      <title>Логика работы SELECT FOR UPDATE</title>
      <pubDate>Wed, 05 Apr 2023 00:01:13 +0000</pubDate>
      <link>https://php.ru/forum/threads/logika-raboty-select-for-update.101303/</link>
      <guid>https://php.ru/forum/threads/logika-raboty-select-for-update.101303/</guid>
      <author>invalid@example.com (polin11)</author>
      <dc:creator>polin11</dc:creator>
      <content:encoded><![CDATA[Использую СУБД PGSQL.<br />
<br />
Нужно получить мин. значение CreateDate из таблицы документ<br />


<div class="bbCodeBlock bbCodeCode">
	<div class="type">Код (Text):</div>
	<div class="code"><ol class="text" style="font-family:monospace;"><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">SELECT MIN(&quot;CreateDate&quot;)</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">FROM &quot;Document&quot;</div></li>
</ol></div>
</div>если минимальная дата &lt; текущей в цикле вешается транзакция и пересчитывается поле CreateDate, достаю записи<br />
таким запросом: <br />


<div class="bbCodeBlock bbCodeCode">
	<div class="type">Код (Text):</div>
	<div class="code"><ol class="text" style="font-family:monospace;"><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">SELECT *</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">FROM &quot;Document&quot;</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">WHERE &quot;CreateDate&quot; &lt; NOW()::DATE</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">ORDER BY &quot;CreateDate&quot;</div></li>
<li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">LIMIT 10</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">FOR UPDATE SKIP LOCKED</div></li>
</ol></div>
</div>Обновление записей<br />


<div class="bbCodeBlock bbCodeCode">
	<div class="type">Код (Text):</div>
	<div class="code"><ol class="text" style="font-family:monospace;"><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">UPDATE &quot;Document&quot;</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">SET &quot;CreateDate&quot; = ...</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">...</div></li>
</ol></div>
</div><br />
Насколько понимаю логику...<br />
<br />
<a href="https://php.ru/forum/threads/logika-raboty-select-for-update.101303/" class="internalLink">Логика работы SELECT FOR UPDATE</a>]]></content:encoded>
    </item>
    <item>
      <title>База выдает несколько ответов и глохнет</title>
      <pubDate>Tue, 04 Apr 2023 11:27:10 +0000</pubDate>
      <link>https://php.ru/forum/threads/baza-vydaet-neskolko-otvetov-i-gloxnet.101289/</link>
      <guid>https://php.ru/forum/threads/baza-vydaet-neskolko-otvetov-i-gloxnet.101289/</guid>
      <author>invalid@example.com (BAPBAP)</author>
      <dc:creator>BAPBAP</dc:creator>
      <content:encoded><![CDATA[Собственно САБЖ.<br />
Скрипт вызывает и отображает последнюю запись из таблицы базы данных , работает несколько секунд и вырубается. Сломал голову почему.<br />
вот сам скрипт<br />
<br />
<b>INDEX.PHP</b><br />


<div class="bbCodeBlock bbCodeCode">
	<div class="type">Код (Text):</div>
	<div class="code"><ol class="text" style="font-family:monospace;"><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&lt;?php</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; $cn = pg_connect(&quot;host=localhost port=5432 dbname=db2 user=postgres password=888888&quot;);</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; if($cn)</div></li>
<li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">{</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; echo &quot;База данных - подключена&quot;;</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">}</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; $query = &quot;SELECT * FROM patient1 ORDER BY idpatient DESC LIMIT 1&quot;;</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; $rs = pg_query($cn, $query) or die(&quot;XYU: $query\n&quot;);</div></li>
<li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; $username = date('Y-m-d...</div></li>
</ol></div>
</div><a href="https://php.ru/forum/threads/baza-vydaet-neskolko-otvetov-i-gloxnet.101289/" class="internalLink">База выдает несколько ответов и глохнет</a>]]></content:encoded>
      <slash:comments>25</slash:comments>
    </item>
    <item>
      <title>Сделать 2 поля уникальными, для определённого значения одного из них.</title>
      <pubDate>Mon, 20 Mar 2023 12:39:41 +0000</pubDate>
      <link>https://php.ru/forum/threads/sdelat-2-polja-unikalnymi-dlja-opredeljonnogo-znachenija-odnogo-iz-nix.101255/</link>
      <guid>https://php.ru/forum/threads/sdelat-2-polja-unikalnymi-dlja-opredeljonnogo-znachenija-odnogo-iz-nix.101255/</guid>
      <author>invalid@example.com (polin11)</author>
      <dc:creator>polin11</dc:creator>
      <content:encoded><![CDATA[Использую PGSQL. Есть таблица <br />
<br />
CREATE TABLE forms (<br />
    id serial PRIMARY KEY,<br />
    account INT NOT NULL,<br />
    author text,<br />
    type INT NOT NULL<br />
);<br />
INSERT INTO  forms(account, author, salary) VALUES <br />
(1, &#039;Иванов&#039;, 11),<br />
(2, &#039;Сидоров&#039;, 11),<br />
(3, &#039;Сергеев&#039;, 12)<br />
<br />
Нужно сделать набор полей (account, type) уникальным только для type = 11.<br />
Например обе записи нельзя было бы вставить, так как type = 11<br />
<br />
(1, &#039;Иванов&#039;, 11),<br />
(1, &#039;Сидоров&#039;, 11)<br />
<br />
а например, записи можно было обе вставить, так как type !=...<br />
<br />
<a href="https://php.ru/forum/threads/sdelat-2-polja-unikalnymi-dlja-opredeljonnogo-znachenija-odnogo-iz-nix.101255/" class="internalLink">Сделать 2 поля уникальными, для определённого значения одного из них.</a>]]></content:encoded>
      <slash:comments>1</slash:comments>
    </item>
    <item>
      <title>Операции над массивами</title>
      <pubDate>Tue, 14 Mar 2023 13:22:29 +0000</pubDate>
      <link>https://php.ru/forum/threads/operacii-nad-massivami.101199/</link>
      <guid>https://php.ru/forum/threads/operacii-nad-massivami.101199/</guid>
      <author>invalid@example.com (polin11)</author>
      <dc:creator>polin11</dc:creator>
      <content:encoded><![CDATA[Использую Postgresql<br />
<br />
1) Есть удобная операция конкатенация массива ||, но при такой операции могут быть будут элементов<br />
например array[1,2,3] || array[1,4] -&gt; array[1,2,3,1,4]<br />
Вопрос как объединить 2 массива при этом убрать дубли элементов?<br />
<br />
2) Если ли операция или функция убрать из массива элементы другого массива, то есть<br />
array[1,2,3] - array[1,4] -&gt; array[2,3]?]]></content:encoded>
      <slash:comments>2</slash:comments>
    </item>
    <item>
      <title>Помогите разобраться с медленным запросом</title>
      <pubDate>Wed, 01 Feb 2023 13:13:32 +0000</pubDate>
      <link>https://php.ru/forum/threads/pomogite-razobratsja-s-medlennym-zaprosom.100793/</link>
      <guid>https://php.ru/forum/threads/pomogite-razobratsja-s-medlennym-zaprosom.100793/</guid>
      <author>invalid@example.com (nekit44)</author>
      <dc:creator>nekit44</dc:creator>
      <content:encoded><![CDATA[Всем привет, подскажите новичку<br />
<br />
Есть такой запрос:<br />
<br />


<div class="bbCodeBlock bbCodeCode">
	<div class="type">Код (Text):</div>
	<div class="code"><ol class="text" style="font-family:monospace;"><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">select</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">item_id,</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">( POW((l0 - 0.101), 2) + POW((l1 - 0.101), 2) + POW((l2 - 0.101), 2) + POW((l3 - 0.101), 2) + POW((l4 - 0.101), 2) + POW((l5 - 0.101), 2) ) as similarity,</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">p.filename as filename,</div></li>
<li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; p.path as path</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">from item_descriptions join item p on p.id = item_descriptions.item_id where item_id &lt;&gt; 1 and user_id is null order by similarity asc limit 100</div></li>
</ol></div>
</div>математика считается и присваивается псевдониму similarity в последствии...<br />
<br />
<a href="https://php.ru/forum/threads/pomogite-razobratsja-s-medlennym-zaprosom.100793/" class="internalLink">Помогите разобраться с медленным запросом</a>]]></content:encoded>
      <slash:comments>3</slash:comments>
    </item>
    <item>
      <title>Оптимизировать запрос с array_replace</title>
      <pubDate>Fri, 09 Dec 2022 14:19:16 +0000</pubDate>
      <link>https://php.ru/forum/threads/optimizirovat-zapros-s-array_replace.100758/</link>
      <guid>https://php.ru/forum/threads/optimizirovat-zapros-s-array_replace.100758/</guid>
      <author>invalid@example.com (polin11)</author>
      <dc:creator>polin11</dc:creator>
      <content:encoded><![CDATA[Есть таблица Responsible, столбец  Documents (тип bigint) ид. документа, User(тип []text) - массив пользователей.<br />
Нужно при смене пользователя, обновить этого пользователя в массиве User.<br />
<br />
Есть такой запрос <br />


<div class="bbCodeBlock bbCodeCode">
	<div class="type">Код (Text):</div>
	<div class="code"><ol class="text" style="font-family:monospace;"><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">UPDATE</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &quot;Responsible&quot;</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">SET</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &quot;User&quot; = array_replace(</div></li>
<li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &quot;User&quot;</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; , &nbsp; &nbsp;'Петров'::text</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; , &nbsp; &nbsp;'Иванов'::text</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; )</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">WHERE</div></li>
<li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &quot;Documents&quot; = ANY('{3}') AND</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; array_position(&quot;User&quot;, 'Петров'::text) IS NOT NULL</div></li>
</ol></div>
</div>Но он много потребляет shared hit.<br />
<br />


<div class="bbCodeBlock bbCodeCode">
	<div class="type">Код (Text):</div>
	<div class="code"><ol class="text" style="font-family:monospace;"><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">Update on...</div></li>
</ol></div>
</div><a href="https://php.ru/forum/threads/optimizirovat-zapros-s-array_replace.100758/" class="internalLink">Оптимизировать запрос с array_replace</a>]]></content:encoded>
    </item>
    <item>
      <title>Удалить из массива элементы</title>
      <pubDate>Thu, 15 Sep 2022 22:36:05 +0000</pubDate>
      <link>https://php.ru/forum/threads/udalit-iz-massiva-ehlementy.100146/</link>
      <guid>https://php.ru/forum/threads/udalit-iz-massiva-ehlementy.100146/</guid>
      <author>invalid@example.com (polin11)</author>
      <dc:creator>polin11</dc:creator>
      <content:encoded><![CDATA[Использую СУБД Postgresql.<br />
Есть таблица вида:<br />


<div class="bbCodeBlock bbCodePHP">
	<div class="type">PHP:</div>
	<div class="code"><ol class="php" style="font-family:monospace;"><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">CREATE TABLE docs <span style="color: #009900;">&#40;</span></div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp;id int PRIMARY <a target="_blank" rel="nofollow" href="http://www.php.net/key"><span style="color: #990000;">KEY</span></a><span style="color: #339933;">,</span></div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp;account bigint<span style="color: #339933;">,</span></div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp;contact TEXT <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span></div></li>
<li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">INSERT INTO docs VALUES<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">22</span><span style="color: #339933;">,</span> <a target="_blank" rel="nofollow" href="http://www.php.net/array"><span style="color: #990000;">ARRAY</span></a> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Иван'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Петр'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">INSERT INTO docs VALUES<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">22</span><span style="color: #339933;">,</span> <a target="_blank" rel="nofollow" href="http://www.php.net/array"><span style="color: #990000;">ARRAY</span></a> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Иван'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">INSERT INTO docs VALUES<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">22</span><span style="color: #339933;">,</span> <a target="_blank" rel="nofollow" href="http://www.php.net/array"><span style="color: #990000;">ARRAY</span></a><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Иван'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Виктор'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">INSERT INTO docs values<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">22</span><span style="color: #339933;">,</span> <a target="_blank" rel="nofollow" href="http://www.php.net/array"><span style="color: #990000;">ARRAY</span></a><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Иван'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Роман'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Сергей'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></li>
</ol></div>
</div>Есть массив строк контактов(например [&#039;Иван&#039;,&#039;Петр&#039;]) и аккаунт, нужно из поля contact удалить<br />
этих пользователей. Если после...<br />
<br />
<a href="https://php.ru/forum/threads/udalit-iz-massiva-ehlementy.100146/" class="internalLink">Удалить из массива элементы</a>]]></content:encoded>
    </item>
    <item>
      <title>Убрать из плана seq scan</title>
      <pubDate>Wed, 14 Sep 2022 09:02:14 +0000</pubDate>
      <link>https://php.ru/forum/threads/ubrat-iz-plana-seq-scan.100124/</link>
      <guid>https://php.ru/forum/threads/ubrat-iz-plana-seq-scan.100124/</guid>
      <author>invalid@example.com (polin11)</author>
      <dc:creator>polin11</dc:creator>
      <content:encoded><![CDATA[Использую СУБД PGSQL.<br />
Есть таблица Documents в ней поле Account - целое, User - массив строк.<br />
<br />
Происходит удаление пользователя, нужно этого пользователя удалить из User,<br />
если после удаления массив пустой, то нужно удалить запись.<br />
Написал такой запрос, но он стал жутко тормозить.<br />


<div class="bbCodeBlock bbCodePHP">
	<div class="type">PHP:</div>
	<div class="code"><ol class="php" style="font-family:monospace;"><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">WITH user <span style="color: #b1b100;">AS</span> <span style="color: #009900;">&#40;</span></div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT DISTINCT UNNEST<span style="color: #009900;">&#40;</span><a target="_blank" rel="nofollow" href="http://www.php.net/array"><span style="color: #990000;">ARRAY</span></a><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'27672'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'6145'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">AS</span> <span style="color: #0000ff;">&quot;Id&quot;</span></div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span></div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ar <span style="color: #b1b100;">AS</span><span style="color: #009900;">&#40;</span></div></li>
<li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;@Id&quot;</span> <span style="color: #b1b100;">AS</span> <span style="color: #0000ff;">&quot;Id&quot;</span><span style="color: #339933;">,</span></div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; array_remove<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;User&quot;</span><span style="color: #339933;">,...</span></div></li>
</ol></div>
</div><a href="https://php.ru/forum/threads/ubrat-iz-plana-seq-scan.100124/" class="internalLink">Убрать из плана seq scan</a>]]></content:encoded>
    </item>
    <item>
      <title>insert unnest(array)</title>
      <pubDate>Fri, 26 Aug 2022 08:39:24 +0000</pubDate>
      <link>https://php.ru/forum/threads/insert-unnest-array.99945/</link>
      <guid>https://php.ru/forum/threads/insert-unnest-array.99945/</guid>
      <author>invalid@example.com (k-dimka)</author>
      <dc:creator>k-dimka</dc:creator>
      <content:encoded><![CDATA[Доброго времени суток, уважаемые форумчане, бьюсь головой третий день, суть такова:<br />


<div class="bbCodeBlock bbCodeCode">
	<div class="type">Код (Text):</div>
	<div class="code"><ol class="text" style="font-family:monospace;"><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">public function InsertDoc($numdoc)</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; {</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; // if (!empty($numDoc)) {</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parent::connect();</div></li>
<li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $this-&gt;pdo-&gt;beginTransaction();</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $this-&gt;pdo-&gt;query(&quot;INSERT INTO honestsign (numdoc) VALUES (unnest(array['123','234','1234','234','234','421','421']))&quot;);</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $this-&gt;pdo-&gt;commit();</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $this-&gt;pdo = null;</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp;// &nbsp;}</div></li>
<li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; }</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">}</div></li>
</ol></div>
</div>в таком варианте без проблем...<br />
<br />
<a href="https://php.ru/forum/threads/insert-unnest-array.99945/" class="internalLink">insert unnest(array)</a>]]></content:encoded>
      <slash:comments>1</slash:comments>
    </item>
    <item>
      <title>Ошибка canceling statement due to statement timeout</title>
      <pubDate>Mon, 04 Jul 2022 12:20:04 +0000</pubDate>
      <link>https://php.ru/forum/threads/oshibka-canceling-statement-due-to-statement-timeout.99255/</link>
      <guid>https://php.ru/forum/threads/oshibka-canceling-statement-due-to-statement-timeout.99255/</guid>
      <author>invalid@example.com (polin11)</author>
      <dc:creator>polin11</dc:creator>
      <content:encoded><![CDATA[Использую PGSQL.<br />
Есть таблица записей ~ 1000 000 записей<br />


<div class="bbCodeBlock bbCodeCode">
	<div class="type">Код (Text):</div>
	<div class="code"><ol class="text" style="font-family:monospace;"><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">CRE ATE &nbsp; TABLE forms (</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; id serial PRIMARY KEY,</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; account INT NOT NULL,</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; author text,</div></li>
<li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; salary INT NOT NULL</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">);</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">INS ERT INTO &nbsp;forms(account, author, salary) VALUES</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">(1100889, 'Иванов', 30),</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">(1100889, 'Петров', 40),</div></li>
<li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">(4443, 'Сидоров', 40),</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">(1100889, 'Сергеев', 50)</div></li>
</ol></div>
</div>При авторизации пользователя в аккаунт идет пересчет поля salary в целом по аккаунту для всех пользователей<br />


<div class="bbCodeBlock bbCodeCode">
	<div class="type">Код (Text):</div>
	<div class="code"><ol class="text" style="font-family:monospace;"><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">UPD ATE forms</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">SET salary = (SEL ECT....)...</div></li>
</ol></div>
</div><a href="https://php.ru/forum/threads/oshibka-canceling-statement-due-to-statement-timeout.99255/" class="internalLink">Ошибка canceling statement due to statement timeout</a>]]></content:encoded>
      <slash:comments>1</slash:comments>
    </item>
    <item>
      <title>Ускорить простой запрос</title>
      <pubDate>Wed, 22 Jun 2022 03:25:11 +0000</pubDate>
      <link>https://php.ru/forum/threads/uskorit-prostoj-zapros.99302/</link>
      <guid>https://php.ru/forum/threads/uskorit-prostoj-zapros.99302/</guid>
      <author>invalid@example.com (polin11)</author>
      <dc:creator>polin11</dc:creator>
      <content:encoded><![CDATA[Ускорить простой запрос нужно проверить входят ли ид. записей из массива в таблицу<br />
<br />
<br />


<div class="bbCodeBlock bbCodeCode">
	<div class="type">Код (Text):</div>
	<div class="code"><ol class="text" style="font-family:monospace;"><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">SELECT ARRAY(</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">SELECT &nbsp;DISTINCT &quot;Event&quot;</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; FROM &quot;Documents&quot;</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; WHERE &quot;Event&quot; = ANY(ARRAY[1005657, 1005664, 7122])</div></li>
<li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; LIMIT 3</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">)</div></li>
</ol></div>
</div>Для этого запроса такой план.<br />


<div class="bbCodeBlock bbCodeCode">
	<div class="type">Код (Text):</div>
	<div class="code"><ol class="text" style="font-family:monospace;"><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&quot;Result &nbsp;(cost=0.93..0.94 rows=1 width=32) (actual time=2.110..2.111 rows=1 loops=1)&quot;</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&quot; &nbsp;Buffers: shared hit=213&quot;</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&quot; &nbsp;InitPlan 1 (returns $0)&quot;</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&quot; &nbsp; &nbsp;-&gt; &nbsp;Limit &nbsp;(cost=0.43..0.93 rows=3 width=4) (actual time=0.042..2.100...</div></li>
</ol></div>
</div><a href="https://php.ru/forum/threads/uskorit-prostoj-zapros.99302/" class="internalLink">Ускорить простой запрос</a>]]></content:encoded>
      <slash:comments>1</slash:comments>
    </item>
    <item>
      <title>Замена в jsonb значения</title>
      <pubDate>Sun, 12 Jun 2022 10:23:45 +0000</pubDate>
      <link>https://php.ru/forum/threads/zamena-v-jsonb-znachenija.99226/</link>
      <guid>https://php.ru/forum/threads/zamena-v-jsonb-znachenija.99226/</guid>
      <author>invalid@example.com (polin11)</author>
      <dc:creator>polin11</dc:creator>
      <content:encoded><![CDATA[Использую POSTGRESQL, есть таблица с полем jsonb<br />


<div class="bbCodeBlock bbCodeCode">
	<div class="type">Код (Text):</div>
	<div class="code"><ol class="text" style="font-family:monospace;"><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">select *</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">from</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">(</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">values</div></li>
<li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">(1, '{&quot;name&quot;:[&quot;Иванов&quot;,&quot;Сидоров&quot;], &quot;town&quot;:&quot;Paris&quot;}'::jsonb),</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">(2, '{&quot;name&quot;:[&quot;Иванов&quot;,&quot;Сергеев&quot;], &quot;town&quot;:&quot;Berlin&quot;}'::jsonb),</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">(3, '{&quot;name&quot;:[&quot;Марков&quot;], &quot;town&quot;:&quot;Rome&quot;}'::jsonb)</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">) as q (id, data)</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li>
</ol></div>
</div><a href="https://www.db-fiddle.com/f/dMK5uHZ8Thxnk57hi7f4wN/0" target="_blank" class="externalLink" rel="nofollow">https://www.db-fiddle.com/f/dMK5uHZ8Thxnk57hi7f4wN/0</a><br />
<br />
Нужно в массиве по ключу name заменить Иванов на Петров, в итоге, чтобы <br />


<div class="bbCodeBlock bbCodeCode">
	<div class="type">Код (Text):</div>
	<div class="code"><ol class="text" style="font-family:monospace;"><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">1 &nbsp; &nbsp;{&quot;name&quot;:[&quot;Петров&quot;,&quot;Сидоров&quot;],&quot;town&quot;:&quot;Paris&quot;}</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">2...</div></li>
</ol></div>
</div><a href="https://php.ru/forum/threads/zamena-v-jsonb-znachenija.99226/" class="internalLink">Замена в jsonb значения</a>]]></content:encoded>
    </item>
    <item>
      <title>CTE,  табличное выражение</title>
      <pubDate>Tue, 12 Apr 2022 11:37:55 +0000</pubDate>
      <link>https://php.ru/forum/threads/cte-tablichnoe-vyrazhenie.98582/</link>
      <guid>https://php.ru/forum/threads/cte-tablichnoe-vyrazhenie.98582/</guid>
      <author>invalid@example.com (Dimon2x)</author>
      <dc:creator>Dimon2x</dc:creator>
      <content:encoded><![CDATA[Разбираюсь с рекурсивными запросами, вот пример:<br />
<br />


<div class="bbCodeBlock bbCodeCode">
	<div class="type">Код (Text):</div>
	<div class="code"><ol class="text" style="font-family:monospace;"><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">create table employees</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">(</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; id &nbsp; &nbsp; &nbsp;serial primary key,</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; name &nbsp; &nbsp;varchar,</div></li>
<li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; manager int references employees</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">);</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">insert into employees (id, name, manager)</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">values (1, 'Kevin Wilkerson', null),</div></li>
<li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp;(2, 'Darin Montgomery', 1),</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp;(3, 'Joyce Campbell', 1),</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp;(4, 'Alfred Brewer', 2),</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp;(5, 'Carroll Jimenez', 3),</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp;(6, 'Jamie Sims', 3),</div></li>
<li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp;(7, 'Nettie Lawrence', 5);</div></li>
</ol></div>
</div>Выборка:<br />
<br />


<div class="bbCodeBlock bbCodeCode">
	<div class="type">Код (Text):</div>
	<div class="code"><ol class="text" style="font-family:monospace;"><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">with recursive...</div></li>
</ol></div>
</div><a href="https://php.ru/forum/threads/cte-tablichnoe-vyrazhenie.98582/" class="internalLink">CTE,  табличное выражение</a>]]></content:encoded>
    </item>
    <item>
      <title>Паттерн eav и запросы для него</title>
      <pubDate>Mon, 07 Feb 2022 15:57:26 +0000</pubDate>
      <link>https://php.ru/forum/threads/pattern-eav-i-zaprosy-dlja-nego.97577/</link>
      <guid>https://php.ru/forum/threads/pattern-eav-i-zaprosy-dlja-nego.97577/</guid>
      <author>invalid@example.com (Dimon2x)</author>
      <dc:creator>Dimon2x</dc:creator>
      <content:encoded><![CDATA[Решил немного потренироваться с БД, придумал таблицы магазина.<br />
Нормализация бд: решил использовать &quot;EAV&quot;.<br />
<br />
Дайте советы по структуре, что нужно исправить и ответьте пожалуйста на некоторые вопросы.<br />
<br />
Придумайте ещё дополнительные задания по этой БД, для меня.<br />
<br />



<div class="ToggleTriggerAnchor bbCodeSpoilerContainer">
	<button class="button bbCodeSpoilerButton ToggleTrigger Tooltip JsOnly"
		title="Нажмите, чтобы раскрыть или скрыть спойлер"
		data-target="> .SpoilerTarget"><span>Спойлер: <span class="SpoilerTitle">Структура</span></span></button>
	<div class="SpoilerTarget bbCodeSpoilerText">

<div class="bbCodeBlock bbCodeCode">
	<div class="type">Код (Text):</div>
	<div class="code"><ol class="text" style="font-family:monospace;"><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">CREATE TABLE category (</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; id smallserial PRIMARY KEY,</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; name_category char(60)</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">);</div></li>
<li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">INSERT INTO category (name_category) VALUES ('Lenovo');</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">INSERT INTO category (name_category) VALUES ('Honor');</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">INSERT...</div></li>
</ol></div>
</div></div>
</div><br />
<a href="https://php.ru/forum/threads/pattern-eav-i-zaprosy-dlja-nego.97577/" class="internalLink">Паттерн eav и запросы для него</a>]]></content:encoded>
      <slash:comments>1</slash:comments>
    </item>
    <item>
      <title>Большый БД. Как ускорить запросы</title>
      <pubDate>Sun, 09 Jan 2022 19:25:40 +0000</pubDate>
      <link>https://php.ru/forum/threads/bolshyj-bd-kak-uskorit-zaprosy.96877/</link>
      <guid>https://php.ru/forum/threads/bolshyj-bd-kak-uskorit-zaprosy.96877/</guid>
      <author>invalid@example.com (DarkU)</author>
      <dc:creator>DarkU</dc:creator>
      <content:encoded><![CDATA[Доброго времени суток.<br />
Есть проект в которого более 3млн новых записей каждый день. БД большая. Для ускорения запросов зделати table partition по месяцам. БД postgresql 12. Но этого уже не хватает. Сервера 60гб RAM, 8k IOPS 100+ CPU.<br />
Какие варианты ускорения работы БД? (реплика read only уже есть. Плодить еще кластеры не хочеться).<br />
Спасибо.<br />
<br />
П.С.<br />
перенесите пожалуйста тему в соответсвующий раздел, спабоси.]]></content:encoded>
      <slash:comments>4</slash:comments>
    </item>
    <item>
      <title>Index для UUID</title>
      <pubDate>Sat, 21 Aug 2021 15:33:06 +0000</pubDate>
      <link>https://php.ru/forum/threads/index-dlja-uuid.94134/</link>
      <guid>https://php.ru/forum/threads/index-dlja-uuid.94134/</guid>
      <author>invalid@example.com (polin11)</author>
      <dc:creator>polin11</dc:creator>
      <content:encoded><![CDATA[Использую Postresql.<br />
Есть таблица Documents с полями:<br />
Account тип bigint <br />
Document тип bigint<br />
User тип UUID<br />
<br />
Есть 2 индекса<br />


<div class="bbCodeBlock bbCodeCode">
	<div class="type">Код (Text):</div>
	<div class="code"><ol class="text" style="font-family:monospace;"><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">CREATE INDEX &quot;AccountDocument&quot; ON &quot;Documents&quot; USING btree (&quot;Account&quot; NULLS LAST, &quot;Document&quot; NULLS LAST)</div></li>
<li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">WHERE (&quot;Account&quot; IS NOT NULL OR &quot;Document&quot; IS NOT NULL);</div></li>
</ol></div>
</div>

<div class="bbCodeBlock bbCodeCode">
	<div class="type">Код (Text):</div>
	<div class="code"><ol class="text" style="font-family:monospace;"><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">CREATE INDEX &quot;AccountUserDocument&quot; ON &quot;Documents&quot; &nbsp;USING btree (&quot;Account&quot;, &quot;User&quot;, &quot;Document&quot;)</div></li>
</ol></div>
</div>Для простого запроса хочу, чтобы использовался индекс AccountUserDocument...<br />
<br />
<a href="https://php.ru/forum/threads/index-dlja-uuid.94134/" class="internalLink">Index для UUID</a>]]></content:encoded>
    </item>
    <item>
      <title>Прокси идентификация Postresql</title>
      <pubDate>Sat, 08 May 2021 13:01:22 +0000</pubDate>
      <link>https://php.ru/forum/threads/proksi-identifikacija-postresql.92278/</link>
      <guid>https://php.ru/forum/threads/proksi-identifikacija-postresql.92278/</guid>
      <author>invalid@example.com (Artur68)</author>
      <dc:creator>Artur68</dc:creator>
      <content:encoded><![CDATA[Подскажите пожалуйста, что подрузумевается под Proxy индетификацией? Если я правильно понимаю, то она позволяет взодить под опреленной ролью в бд, а так же использование SET ROLE?]]></content:encoded>
    </item>
  </channel>
</rss>
