<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Updating variable in huge table A with values from table B in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Updating-variable-in-huge-table-A-with-values-from-table-B/m-p/828213#M327155</link>
    <description>&lt;P&gt;Is t2 a sas dataset or another postgres table?&lt;/P&gt;</description>
    <pubDate>Thu, 11 Aug 2022 06:50:53 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2022-08-11T06:50:53Z</dc:date>
    <item>
      <title>Updating variable in huge table A with values from table B</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating-variable-in-huge-table-A-with-values-from-table-B/m-p/828212#M327154</link>
      <description>&lt;P&gt;We've got a series of large tables in PostgreSQL (over 500 million rows in some). Each table has an attribute called REF_ID, and one called OBJECT_CD. Both are varchar(32).&amp;nbsp;OBJECT_CD is always NULL, but now we need to give it a value (on all rows). Let's call one of these large tables T1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We've also got the table T2. It's a smaller table that contains 1 row per REF_ID. The attribute OBJECT_CD is always filled out here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to update T1.OBJECT_CD with values from T2.OBJECT_CD (where T1.REF_ID = T2.REF_ID).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sounds simple, but I have a hard time finding an effective way to do it. The PostgreSQL tables are so large, and the code I've tried runs "forever" and times out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An example of something I've tried:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	update pgsql.T1
	set OBJECT_CD = (select distinct OBJECT_CD
		from T2
		where T1.REF_ID = T2.REF_ID);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Any advice on the most effective way to update huge PostgreSQL tables?&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 06:44:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating-variable-in-huge-table-A-with-values-from-table-B/m-p/828212#M327154</guid>
      <dc:creator>EinarRoed</dc:creator>
      <dc:date>2022-08-11T06:44:42Z</dc:date>
    </item>
    <item>
      <title>Re: Updating variable in huge table A with values from table B</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating-variable-in-huge-table-A-with-values-from-table-B/m-p/828213#M327155</link>
      <description>&lt;P&gt;Is t2 a sas dataset or another postgres table?&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 06:50:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating-variable-in-huge-table-A-with-values-from-table-B/m-p/828213#M327155</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-08-11T06:50:53Z</dc:date>
    </item>
    <item>
      <title>Re: Updating variable in huge table A with values from table B</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating-variable-in-huge-table-A-with-values-from-table-B/m-p/828218#M327156</link>
      <description>&lt;P&gt;T2 is a SAS dataset.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 07:16:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating-variable-in-huge-table-A-with-values-from-table-B/m-p/828218#M327156</guid>
      <dc:creator>EinarRoed</dc:creator>
      <dc:date>2022-08-11T07:16:03Z</dc:date>
    </item>
    <item>
      <title>Re: Updating variable in huge table A with values from table B</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating-variable-in-huge-table-A-with-values-from-table-B/m-p/828219#M327157</link>
      <description>&lt;P&gt;Try loading it to the DB and do the entire update there.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 07:16:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating-variable-in-huge-table-A-with-values-from-table-B/m-p/828219#M327157</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-08-11T07:16:28Z</dc:date>
    </item>
    <item>
      <title>Re: Updating variable in huge table A with values from table B</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating-variable-in-huge-table-A-with-values-from-table-B/m-p/828221#M327158</link>
      <description>&lt;P&gt;As others suggested load the small table into Postgres and then execute everything in-database. Code close to below should work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let pg_libref=pgsql;
%let pg_schema=;
proc sql noprint;
  select sysvalue into :pg_schema trimmed
  from dictionary.libnames
  where
    libname="%upcase(&amp;amp;pg_libref)"
    and sysname='Schema/Owner'
  ;
quit;

proc datasets lib=&amp;amp;pg_libref nolist nowarn;
  delete T2;
run;quit;

proc append data=work.t2 base=&amp;amp;pg_libref..t2;
run;quit;

proc sql;
  connect using &amp;amp;pg_libref as pg;
  execute
  (
	update &amp;amp;pg_schema..T1
  	set OBJECT_CD = (  select OBJECT_CD
                  		from &amp;amp;pg_schema..T2
  		                where T1.REF_ID = T2.REF_ID)
    ;
  ) by pg;
  disconnect from pg;
quit;

proc datasets lib=&amp;amp;pg_libref nolist nowarn;
  delete T2;
run;quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Aug 2022 08:47:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating-variable-in-huge-table-A-with-values-from-table-B/m-p/828221#M327158</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-08-11T08:47:58Z</dc:date>
    </item>
    <item>
      <title>Re: Updating variable in huge table A with values from table B</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating-variable-in-huge-table-A-with-values-from-table-B/m-p/828224#M327160</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/33000"&gt;@EinarRoed&lt;/a&gt;&amp;nbsp;I've added a few obvious fixes to the post you already accepted as solution. Still totally untested code of course but I've used something similar in a real implementation where things work.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 08:49:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating-variable-in-huge-table-A-with-values-from-table-B/m-p/828224#M327160</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-08-11T08:49:42Z</dc:date>
    </item>
  </channel>
</rss>

