--0-1294299445-1106073251=:26396 Content-Type: text/plain; charset=us-ascii
Hi All, Is it possible to "generate" dynamic queries using pl/pgsql? I am trying to archive a set of tables: affiliate_event, affiliate_batch, affiliate_batch_details, affiliate_daily_batch, affiliate_daily_batch_details. The following steps are necessary for each table: 1) select the data from the table based on the date (and other clause), and Move that data to a temporary table 2) Dump the temp table to a file 3) Delete the data from the original table 4) Delete the temporary table. Is it possible for pl/pgsql to dynamically generate the SQL select queries needed in step 1?? What information/input would it need in that case? These are the step 1 queries I am using: create table temp1 as select * from affiliate_batch where tx_dt < '12/31/2003'; ... delete from temp1; -------------------------------------------------------------------------------------------------------------------------------- create table temp1 as select bd.* from affiliate_batch_details bd join affiliate_batch b on bd.batch_id=b.id where b.tx_dt < '12/31/2003' order by bd.batch_id; ... delete from temp1; -------------------------------------------------------------------------------------------------------------------------------- create table temp1 as select adb.* from affiliate_daily_batch adb join affiliate_batch b on adb.monthly_batch_id=b.id where b.tx_dt < '12/31/2003' order by adb.monthly_batch_id; ... delete from temp1; --------------------------------------------------------------------------------------------------------------------------------- create table temp1 as select adb.* from affiliate_daily_batch_details adb where exists (select ad.id from affiliate_daily_batch ad join affiliate_batch b on ad.monthly_batch_id=b.id where adb.batch_id=ad.id and b.tx_dt < '12/31/2003' order by ad.monthly_batch_id) order by adb.batch_id; ... delete from temp1; ---------------------------------------------------------------------------------------------------------------------------------
create table temp1 as select * from affiliate_event where dt<'12/31/2003'; ... delete from temp1; --------------------------------------------------------------------------------------------------------------------------------- Thanks in advance! Saranya
__________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com --0-1294299445-1106073251=:26396 Content-Type: text/html; charset=us-ascii
Hi All,
Is it possible to "generate" dynamic queries using pl/pgsql?
I am trying to archive a set of tables: affiliate_event, affiliate_batch, affiliate_batch_details, affiliate_daily_batch, affiliate_daily_batch_details.
The following steps are necessary for each table:
1) select the data from the table based on the date (and other clause), and Move that data to a temporary table
2) Dump the temp table to a file
3) Delete the data from the original table
4) Delete the temporary table.
Is it possible for pl/pgsql to dynamically generate the SQL select queries needed in step 1??
What information/input would it need in that case?
These are the step 1 queries I am using:
create table temp1 as select * from affiliate_batch where tx_dt < '12/31/2003';
..
delete from temp1;
--------------------------------------------------------------------------------------------------------------------------------
create table temp1 as select bd.* from affiliate_batch_details bd join affiliate_batch b on bd.batch_id=b.id where b.tx_dt < '12/31/2003' order by bd.batch_id;
..
delete from temp1;
--------------------------------------------------------------------------------------------------------------------------------
create table temp1 as select adb.* from affiliate_daily_batch adb join affiliate_batch b on adb.monthly_batch_id=b.id where b.tx_dt < '12/31/2003' order by adb.monthly_batch_id;
..
delete from temp1;
---------------------------------------------------------------------------------------------------------------------------------
create table temp1 as select adb.* from affiliate_daily_batch_details adb where exists (select ad.id from affiliate_daily_batch ad join affiliate_batch b on ad.monthly_batch_id=b.id where adb.batch_id=ad.id and b.tx_dt < '12/31/2003' order by ad.monthly_batch_id) order by adb.batch_id;
.. delete from temp1; ---------------------------------------------------------------------------------------------------------------------------------
create table temp1 as select * from affiliate_event where dt<'12/31/2003';
.. delete from temp1; --------------------------------------------------------------------------------------------------------------------------------- Thanks in advance! Saranya __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com --0-1294299445-1106073251=:26396--
|