| |
|
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.
|
 |

01-25-12, 14:55
|
|
∞∞∞∞∞∞
|
|
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
|
|
|
generate runstats command
|
|
I used the following to generate the runstats command for all tables:
db2 -x "select 'runstats on table '|| rtrim(tabschema) || '.' || rtrim(tabname)||' with distribution on key columns and detailed indexes all;' from syscat.tables where type = 'T'" > runstats.sql
But it doesn't work for tables such as CANDLE.KLZ_CPU_Averages_M (mixed case) or CANDLE.Application_Transaction/Program_Long-Term_History (special char).
The following generates the runstats command that works but would like to know if there is a better way to accomplish the same:
db2 -x "select 'runstats on table '|| rtrim(tabschema) || '.\' || '\"' || rtrim(tabname)|| '\' || '\"' ||' with distribution on key columns and detailed indexes all;' from syscat.tables where type = 'T'" > runstats.sql
This generates:
runstats on table CANDLE.\"KLZ_CPU_Averages_M\" with distribution on key columns and detailed indexes all;
Can you please suggest a better way to generate the runstats command?
|
|

01-25-12, 15:14
|
|
∞∞∞∞∞∞
|
|
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
|
|
Actually, for it to work with db2 -tvf, I just need the double quotes:
runstats on table CANDLE."KLZ_CPU_Averages_M" with distribution on key columns and detailed indexes all;
But with ksh, I need:
db2 runstats on table CANDLE.\"KLZ_CPU_Averages_M\" with distribution on key columns and detailed indexes all
Please suggest how to improve the following:
db2 -x "select 'db2 runstats on table '|| rtrim(tabschema) || '.\' || '\"' || rtrim(tabname)|| '\' || '\"' ||' with distribution on key columns and
detailed indexes all' from syscat.tables where type = 'T'" > runstats.sql
|
|

01-25-12, 17:02
|
|
Registered User
|
|
Join Date: May 2003
Location: USA
Posts: 5,198
|
|
|
|
At first glance your generate runstats SQL looks fine.
I would find the person who created the case-sensitive table names and send them to Singapore for caning.
LiveLeak.com - Caning in Singapore
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
|
|

01-25-12, 19:56
|
|
Registered User
|
|
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
|
|
Or you get used to the fact that all database systems allow delimited identifiers these days and start to always use the double-quotes. ;-)
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
|
|

01-26-12, 02:58
|
|
Registered User
|
|
Join Date: Jan 2009
Location: Zoetermeer, Holland
Posts: 555
|
|
Tut mir leid Knut, I vote for the Singapore option 
|
|

01-26-12, 09:48
|
|
∞∞∞∞∞∞
|
|
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
|
|
There is no better way to generate: \" and \" ?
These tables are part of Tivoli Data Warehouse product. Caning is way too severe and I read it can't be used for women and men over 50.
|
|

01-26-12, 13:44
|
|
Registered User
|
|
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
|
|
I would probably wrap the formatting into a simple SQL UDF, which does the concatenation and wrapping into ". Then you call this UDF:
Code:
SELECT 'db2 runstats on table '|| format_table_name(tabschema, tabname) || ' with distribution on key columns and detailed indexes all'
FROM syscat.tables where type = 'T'
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
|
|

01-26-12, 20:14
|
|
∞∞∞∞∞∞
|
|
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
|
|
Quote:
Originally Posted by stolze
I would probably wrap the formatting into a simple SQL UDF, which does the concatenation and wrapping into ".
|
I've never written one before. Could you please show an example of format_table_name?
|
|

01-26-12, 20:29
|
|
∞∞∞∞∞∞
|
|
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
|
|
This site has some bug. This is a new thread, but it's got so many Views...
|
|

01-26-12, 21:50
|
|
Registered User
|
|
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
|
|
I don't have a DB2 instance at hand right now. So here is an untested version:
Code:
CREATE FUNCTION format_table_name(schemaName VARCHAR(128), tableName VARCHAR(128))
RETURNS VARCHAR(261)
LANGUAGE SQL
DETERMINISTIC
CONTAINS SQL
RETURN '"' || RTRIM(schemaName) || '"."' || RTRIM(tableName) || '"'
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
|
|

01-27-12, 07:05
|
|
Registered User
|
|
Join Date: May 2003
Location: USA
Posts: 5,198
|
|
I personally don't think it is a good idea for any DBA maint scripts to rely on custom functions, views, etc that are not part of the DB. This is especially true for databases created by vendor packages.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|