<?xml version='1.0' encoding="utf-8"?>
      <rss version='2.0'>
      <channel>
      <title>Форум на Исходниках.RU</title>
      <link>https://forum.sources.ru</link>
      <description>Форум на Исходниках.RU</description>
      <generator>Форум на Исходниках.RU</generator>
  	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=408397&amp;view=findpost&amp;p=3661264</guid>
        <pubDate>Wed, 23 Mar 2016 20:16:54 +0000</pubDate>
        <title>UPDATE SELECT</title>
        <link>https://forum.sources.ru/index.php?showtopic=408397&amp;view=findpost&amp;p=3661264</link>
        <description><![CDATA[grgdvo: Вы можете делать JOIN практически также как в SELECT. Например<br>
<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">update t1 set (f1, f2) = (t2.f1, t2.f2)</div><div class="code_line">from t2, t3 where t1.id = t2.f1 and t2.f2 = t3.id;</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script><br>
<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">update t1 set (f1, f2) = (t2.f1, t2.f2)</div><div class="code_line">from t2 left join t3 on t2.f2 = t3.id where t1.id = t2.f1;</div></ol></div></div></div></div>]]></description>
        <author>grgdvo</author>
        <category>Базы данных: SQL</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=408397&amp;view=findpost&amp;p=3661253</guid>
        <pubDate>Wed, 23 Mar 2016 18:21:06 +0000</pubDate>
        <title>UPDATE SELECT</title>
        <link>https://forum.sources.ru/index.php?showtopic=408397&amp;view=findpost&amp;p=3661253</link>
        <description><![CDATA[HighMan: <div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">update t1 set (f1, f2) = (t2.f1, t2.f2)</div><div class="code_line">&nbsp;</div><div class="code_line">from t2 where t1.id = t2.f1;</div></ol></div></div></div></div><br>
Такой способ работает, но я не представляю как подобным запросом обрабатывать связи таблиц источников.]]></description>
        <author>HighMan</author>
        <category>Базы данных: SQL</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=408397&amp;view=findpost&amp;p=3661208</guid>
        <pubDate>Wed, 23 Mar 2016 12:10:46 +0000</pubDate>
        <title>UPDATE SELECT</title>
        <link>https://forum.sources.ru/index.php?showtopic=408397&amp;view=findpost&amp;p=3661208</link>
        <description><![CDATA[grgdvo: MIF, t1 нельзя указывать и под UPDATE и под FROM.<br>
<br>
HighMan, попробуйте вот так, вроде эквивалентно<br>
<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">update t1 set (f1, f2) = (t2.f1, t2.f2)</div><div class="code_line">from t2 where t1.id = t2.f1;</div></ol></div></div></div></div>]]></description>
        <author>grgdvo</author>
        <category>Базы данных: SQL</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=408397&amp;view=findpost&amp;p=3661160</guid>
        <pubDate>Wed, 23 Mar 2016 08:31:52 +0000</pubDate>
        <title>UPDATE SELECT</title>
        <link>https://forum.sources.ru/index.php?showtopic=408397&amp;view=findpost&amp;p=3661160</link>
        <description><![CDATA[MIF: Попробуй такой запрос:<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">update t1 </div><div class="code_line">set t1.f1= t2.f1, </div><div class="code_line">t1.f2 = &nbsp;t2.f2 </div><div class="code_line">from t1 </div><div class="code_line">right join t2 on t1.id = t2.f1</div></ol></div></div></div></div>]]></description>
        <author>MIF</author>
        <category>Базы данных: SQL</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=408397&amp;view=findpost&amp;p=3661135</guid>
        <pubDate>Wed, 23 Mar 2016 07:09:38 +0000</pubDate>
        <title>UPDATE SELECT</title>
        <link>https://forum.sources.ru/index.php?showtopic=408397&amp;view=findpost&amp;p=3661135</link>
        <description><![CDATA[HighMan: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=408397&view=findpost&p=3661094'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>grgdvo &#064; <time class="tag-quote__quoted-time" datetime="2016-03-22T20:20:25+00:00">22.03.16, 20:20</time></span><div class='quote '></div></div><br>
Я в топе указал, что PostgreSQL 9.4.<br>
Печально, что вышеприведенная конструкция работает лишь с 9.5.<br>
Но должна же быть схожая конструкция для младших версий.<br>
Вариант с where = (SELECT ...) не интересен.<br>
Нужно обновление таблицы данными и по условию выборки из других таблиц.]]></description>
        <author>HighMan</author>
        <category>Базы данных: SQL</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=408397&amp;view=findpost&amp;p=3661094</guid>
        <pubDate>Tue, 22 Mar 2016 20:20:25 +0000</pubDate>
        <title>UPDATE SELECT</title>
        <link>https://forum.sources.ru/index.php?showtopic=408397&amp;view=findpost&amp;p=3661094</link>
        <description><![CDATA[grgdvo: какая версия PG у вас?? Такой синтаксис <a class='tag-url' href='http://www.postgresql.org/docs/9.5/static/release-9-5.html' target='_blank'>только начиная с 9.5</a>]]></description>
        <author>grgdvo</author>
        <category>Базы данных: SQL</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=408397&amp;view=findpost&amp;p=3660996</guid>
        <pubDate>Tue, 22 Mar 2016 12:19:42 +0000</pubDate>
        <title>UPDATE SELECT</title>
        <link>https://forum.sources.ru/index.php?showtopic=408397&amp;view=findpost&amp;p=3660996</link>
        <description><![CDATA[HighMan: <div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">create table t1 (id integer, f1 integer, f2 integer);</div><div class="code_line">create table t2 (f1 integer, f2 integer);</div><div class="code_line">&nbsp;</div><div class="code_line">update t1 set (f1, f2) = </div><div class="code_line">(select t2.f1, t2.f2 from t1 right join t2 on t1.id = t2.f1);</div></ol></div></div></div></div><br>
[Err] ОШИБКА:  ошибка синтаксиса (примерное положение: &quot;SELECT&quot;)<br>
LINE 2: (SELECT<br>
         ^<br>
Я никак не могу сообразить, как правильно обновлять значения в таблице на основании результатов SELECT .. FROM .. JOIN.<br>
Подскажите пожалуйста&#33; :wall:]]></description>
        <author>HighMan</author>
        <category>Базы данных: SQL</category>
      </item>
	
      </channel>
      </rss>
	