[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 := 'temp_table_';<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 :='temp_table_';<br>ttb := ttb || \
i;<br><br>---union tables<br><br>mystring := 'select * from' || ' \
temp_table_' || i<br>' union '<br>|| 'select * from' || ' \
temp_table_' || i+1;<br><br>End LOOP;<br><br>mystring := 'insert into \
temp_table_1' + 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