If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > V9.5 Truncating partitioned table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-16-10, 09:02
mathew.eldho mathew.eldho is offline
Registered User
 
Join Date: Jan 2007
Location: Pune, India
Posts: 27
V9.5 Truncating partitioned table

Hello

Our environment is DB2 V9.5.

We were trying create a user defined function for datastage people to deleting the data from partitioned table. Datastage people are expecting to use it as follows,

SELECT TRUNCATE_TABLE_PARTITION('p_table_name','p_suffix' ) from sysibm.sysdummy1;

Please see the last conclusion for further details ....
__________________
Eldho Mathew
IBM DB2 UDB LUW Software Engineer

Last edited by mathew.eldho; 06-18-10 at 04:55.
Reply With Quote
  #2 (permalink)  
Old 06-16-10, 09:52
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Do you want the UDF to return the number of rows deleted?

Andy
Reply With Quote
  #3 (permalink)  
Old 06-16-10, 10:03
mathew.eldho mathew.eldho is offline
Registered User
 
Join Date: Jan 2007
Location: Pune, India
Posts: 27
No... we just have to delete

Hello

Thank you very much for response.

We don't need to return anything... we just need to delete them.

Regards,
Eldho Mathew
__________________
Eldho Mathew
IBM DB2 UDB LUW Software Engineer
Reply With Quote
  #4 (permalink)  
Old 06-16-10, 10:06
mathew.eldho mathew.eldho is offline
Registered User
 
Join Date: Jan 2007
Location: Pune, India
Posts: 27
Truncate table rows..

When we run the following query.. it just have to read the table rows and delete them..

SELECT TRUNCATE_TABLE_PARTITION('p_table_name','p_suffix' ) from sysibm.sysdummy1;

Input is Table name and column name.

Thanks,

Eldho Mathew
__________________
Eldho Mathew
IBM DB2 UDB LUW Software Engineer
Reply With Quote
  #5 (permalink)  
Old 06-16-10, 10:50
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Is there a reason why you are implementing it as a UDF, and not as a stored procedure? Stored procedures usually have fewer restrictions for the kinds of statements you can use.
Reply With Quote
  #6 (permalink)  
Old 06-16-10, 11:19
mathew.eldho mathew.eldho is offline
Registered User
 
Join Date: Jan 2007
Location: Pune, India
Posts: 27
content removed....
Thanks for your help.

content removed....
Thanks for your help.content removed....
Thanks for your help.
content removed....
Thanks for your help.content removed....
Thanks for your help.content removed....
Thanks for your help.
__________________
Eldho Mathew
IBM DB2 UDB LUW Software Engineer

Last edited by mathew.eldho; 06-18-10 at 04:53.
Reply With Quote
  #7 (permalink)  
Old 06-16-10, 11:26
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Why not do the work in a stored procedure and create a UDF wrapper around the SP?

Andy
Reply With Quote
  #8 (permalink)  
Old 06-16-10, 11:33
mathew.eldho mathew.eldho is offline
Registered User
 
Join Date: Jan 2007
Location: Pune, India
Posts: 27
Hello

Our data stage team demands for the same so that they can issue a query as they had in Oracle.

SELECT TRUNCATE_TABLE_PARTITION('p_table_name','p_suffix' ) from sysibm.sysdummy1

We also considered trying the following general methods..... not sure any of them will help us here.

1. IMPORT FROM /dev/null OF DEL REPLACE INTO tablename
2. ALTER TABLE <> NOT LOGGED INITIALLY WITH EMPTY TABLE;
commit;
3. CALL ADMIN_CMD('IMPORT FROM /dev/null OF DEL REPLACE INTO tablename')

Implementing the same functionality is important for our business.... let me know if you have any thoughts... thanks a lot for your help.
__________________
Eldho Mathew
IBM DB2 UDB LUW Software Engineer

Last edited by mathew.eldho; 06-16-10 at 11:52.
Reply With Quote
  #9 (permalink)  
Old 06-16-10, 22:44
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
sample stored proc that can be used to truncate a table using import from /dev/null. See truncate.db2:

http://publib.boulder.ibm.com/infoce.../r0007633.html
Reply With Quote
  #10 (permalink)  
Old 06-16-10, 23:02
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
Is it possible to truncate a partition within a Table?

Currently I have to do this:
  • detach the partition into a separate table
  • truncate the separate table
  • re-attach the partition using the now empty table

But I would like give ETL team authority to remove all rows within a partition with only DELETE authority (and without logging due to large number of rows involved).
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #11 (permalink)  
Old 06-17-10, 05:07
mathew.eldho mathew.eldho is offline
Registered User
 
Join Date: Jan 2007
Location: Pune, India
Posts: 27
@ Andy

Hello Andy,

I tried as you recommended..

1. Created a stored procedure as same as UDF mentioned above.
2. Created a function to wrap up... like,

CREATE FUNCTION TRUNCATE_EDWTABLE_PARTITION(p_table_name VARCHAR(100), p_partition_suffix VARCHAR(100))
RETURNS DECIMAL
LANGUAGE SQL
MODIFIES SQL DATA
SPECIFIC TRUNCATE_EDWTABLE_PARTITION
BEGIN ATOMIC
CALL TRUNCATE_TP(p_table_name,p_partition_suffix);
RETURN 0;
END @

This gives...

/sp> db2 -td@ -f tf.sql
DB21034E The command was processed as an SQL statement because it was not avalid Command Line Processor command. During SQL processing it returned:
SQL0270N Function not supported (Reason code = "71"). LINE NUMBER=7. SQLSTATE=42997

=> 71
In a parallel environment, do not use CALL statement in a trigger, a SQL function, a SQL method or a dynamic compound statement.

Refer:- http://publib.boulder.ibm.com/infoce.../t0011377.html

When invoking a procedure from within an SQL trigger, an SQL routine, or a dynamic compound statement the following restrictions apply:
* In partitioned database environments procedures cannot be invoked from triggers or SQL UDFs.

Please let me know if you have any suggestions... thanks
__________________
Eldho Mathew
IBM DB2 UDB LUW Software Engineer

Last edited by mathew.eldho; 06-17-10 at 05:30.
Reply With Quote
  #12 (permalink)  
Old 06-17-10, 05:33
mathew.eldho mathew.eldho is offline
Registered User
 
Join Date: Jan 2007
Location: Pune, India
Posts: 27
@ db2girl

Thanks for your help.

If we cannot invoke Stored proc from UDF ... not sure if this help me.

Let me know if you have something in your mind..
__________________
Eldho Mathew
IBM DB2 UDB LUW Software Engineer
Reply With Quote
  #13 (permalink)  
Old 06-17-10, 10:11
mathew.eldho mathew.eldho is offline
Registered User
 
Join Date: Jan 2007
Location: Pune, India
Posts: 27
It's not possible for our DS users at the moment

content removed....
Thanks for your help.
__________________
Eldho Mathew
IBM DB2 UDB LUW Software Engineer

Last edited by mathew.eldho; 06-18-10 at 04:55.
Reply With Quote
  #14 (permalink)  
Old 06-17-10, 11:18
mathew.eldho mathew.eldho is offline
Registered User
 
Join Date: Jan 2007
Location: Pune, India
Posts: 27
One more question..

One more question...
Can we call a db2 stored procedure in select statement?

Kind Regards,
Eldho Mathew
__________________
Eldho Mathew
IBM DB2 UDB LUW Software Engineer
Reply With Quote
  #15 (permalink)  
Old 06-17-10, 11:33
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Quote:
Originally Posted by mathew.eldho View Post
One more question...
Can we call a db2 stored procedure in select statement?

Kind Regards,
Eldho Mathew
No you cannot.

Andy
Reply With Quote
Reply

Tags
truncate table

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On