[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgis-users
Subject:    [postgis-users] Union a number of tables in a do loop
From:       Shaozhong SHI <shishaozhong () gmail ! com>
Date:       2020-04-14 13:15:35
Message-ID: CA+i5JwYpnB5ccOuFBAeWQ7Ng7RzF=QT-eQP299wOdvU1e6dnXQ () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


I have a number of tables called:
temp_table_1
temp_table_2
temp_table_3
temp_table_4
temp_table_5

Can I do something like this?

Do $$

DECLARE

ttb text := 'temp_table_';

counter integer :=1;
i integer :=0;


mystring text;

BEGIN

For counter IN 2..4 LOOP      -----22 LOOP
i := counter;

ttb :='temp_table_';
ttb := ttb || i;

---union tables

mystring := 'select * from' || ' temp_table_' || i
' union '
|| 'select * from' || ' temp_table_' || i+1;

End LOOP;

mystring := 'insert into temp_table_1' + mystring;

execute mystring;

END $$;

Can anyone help?

Regards,

Shao

[Attachment #5 (text/html)]

<div dir="ltr">I have a number of tables \
called:<div>temp_table_1</div><div>temp_table_2</div><div>temp_table_3</div><div>temp_table_4</div><div>temp_table_5</div><div><br></div><div>Can \
I do something like this?</div><div><br></div><div>Do $$<br><br>DECLARE<br><br>ttb \
text := &#39;temp_table_&#39;;<br><br>counter integer :=1;<br>i integer \
:=0;<br><br><br>mystring text;<br><br>BEGIN<br><br>For counter IN 2..4 LOOP         \
-----22 LOOP<br>i := counter;<br><br>ttb :=&#39;temp_table_&#39;;<br>ttb := ttb || \
i;<br><br>---union tables<br><br>mystring := &#39;select * from&#39; || &#39; \
temp_table_&#39; || i<br>&#39; union &#39;<br>|| &#39;select * from&#39; || &#39; \
temp_table_&#39; || i+1;<br><br>End LOOP;<br><br>mystring := &#39;insert into \
temp_table_1&#39; + mystring;<br><br>execute mystring;<br><br>END \
$$;</div><div><br></div><div>Can anyone \
help?</div><div><br></div><div>Regards,</div><div><br></div><div>Shao<br><br></div></div>



[Attachment #6 (text/plain)]

_______________________________________________
postgis-users mailing list
postgis-users@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/postgis-users

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic