dbTalk Databases Forums  

Comments in a LOAD command?

comp.databases.ibm-db2 comp.databases.ibm-db2


Discuss Comments in a LOAD command? in the comp.databases.ibm-db2 forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Doug B
 
Posts: n/a

Default Comments in a LOAD command? - 02-24-2011 , 11:12 AM






I've learned to live with the cryptic but powerful syntax of the DB2 LOAD command, but I wish there was a way to sprinkle comments inside it, like so:

LOAD CLIENT FROM /path/to/file OF ASC MODIFIED BY BINARYNUMERICS
PACKEDDECIMAL USEDEFAULTS CODEPAGE=37 RECLEN=2920
METHOD L (
01 04, -- col01: id
05 10, -- col02: desc
11 11, -- col03: status_ind
12 21, -- col04: status_short_txt
22 40, -- col05: status_long_txt
....)

Any clever ideas/hacks out there, outside of a pre-processor to remove the comments before sending them to DB2?

Thanks...

Reply With Quote
  #2  
Old   
comet
 
Posts: n/a

Default Re: Comments in a LOAD command? - 03-02-2011 , 09:17 AM






On 2011-02-24, Doug B <blabes (AT) gmail (DOT) com> wrote:
Quote:
I've learned to live with the cryptic but powerful syntax of the
DB2 LOAD command,
but I wish there was a way to sprinkle comments inside it, like so:

LOAD CLIENT FROM /path/to/file OF ASC MODIFIED BY BINARYNUMERICS
PACKEDDECIMAL USEDEFAULTS CODEPAGE=37 RECLEN=2920
METHOD L (
01 04, -- col01: id
05 10, -- col02: desc
11 11, -- col03: status_ind
12 21, -- col04: status_short_txt
22 40, -- col05: status_long_txt
...)

Any clever ideas/hacks out there, outside of a pre-processor to remove
the comments before sending them to DB2?

First of all I recommend the NONRECOVERABLE and REPLACE options for all
loads to keep from filling up log files.

Second I recommend ending all DB2 sessions with a TERMINATE command to
keep from tying up the database.

To get to your question one can use standard unix command line utilities.

Here is a unix session using the cat and sed commands:

$ cat old.sql

LOAD CLIENT FROM /path/to/file OF ASC MODIFIED BY BINARYNUMERICS
PACKEDDECIMAL USEDEFAULTS CODEPAGE=37 RECLEN=2920
METHOD L (
01 04, -- col01: id
05 10, -- col02: desc
11 11, -- col03: status_ind
12 21, -- col04: status_short_txt
22 40, -- col05: status_long_txt
....)

$ cat old.sql | sed -e 's/--.*//'

LOAD CLIENT FROM /path/to/file OF ASC MODIFIED BY BINARYNUMERICS
PACKEDDECIMAL USEDEFAULTS CODEPAGE=37 RECLEN=2920
METHOD L (
01 04,
05 10,
11 11,
12 21,
22 40,
....)

$ cat old.sql | sed -e 's/--.*//' > new.sql
$ cat new.sql

LOAD CLIENT FROM /path/to/file OF ASC MODIFIED BY BINARYNUMERICS
PACKEDDECIMAL USEDEFAULTS CODEPAGE=37 RECLEN=2920
METHOD L (
01 04,
05 10,
11 11,
12 21,
22 40,
....)


comet.berkeley aT gmail D0t com
--
---------------------------------------------------------------------
Don't knock President Fillmore. He kept us out of Vietnam.

Reply With Quote
  #3  
Old   
whatever
 
Posts: n/a

Default Re: Comments in a LOAD command? - 03-02-2011 , 09:24 AM



On Mar 2, 10:17*am, comet <comet.invalid-invalid> wrote:
Quote:
On 2011-02-24, Doug B <bla... (AT) gmail (DOT) com> wrote:





I've learned to live with the cryptic but powerful syntax of the
DB2 LOAD command,
but I wish there was a way to sprinkle comments inside it, like so:

LOAD CLIENT FROM /path/to/file OF ASC MODIFIED BY BINARYNUMERICS
PACKEDDECIMAL USEDEFAULTS CODEPAGE=37 RECLEN=2920
METHOD L (
* 01 04, -- col01: id
* 05 10, -- col02: desc
* 11 11, -- col03: status_ind
* 12 21, -- col04: status_short_txt
* 22 40, -- col05: status_long_txt
...)

Any clever ideas/hacks out there, outside of a pre-processor to remove
the comments before sending them to DB2?

First of all I recommend the NONRECOVERABLE and REPLACE options for all
loads to keep from filling up log files.

Second I recommend ending all DB2 sessions with a TERMINATE command to
keep from tying up the database.

To get to your question one can use standard unix command line utilities.

Here is a unix session using the cat and sed commands:

$ cat old.sql

LOAD CLIENT FROM /path/to/file OF ASC MODIFIED BY BINARYNUMERICS
PACKEDDECIMAL USEDEFAULTS CODEPAGE=37 RECLEN=2920
METHOD L (
* 01 04, -- col01: id
* 05 10, -- col02: desc
* 11 11, -- col03: status_ind
* 12 21, -- col04: status_short_txt
* 22 40, -- col05: status_long_txt
...)

$ cat old.sql | sed -e 's/--.*//'

LOAD CLIENT FROM /path/to/file OF ASC MODIFIED BY BINARYNUMERICS
PACKEDDECIMAL USEDEFAULTS CODEPAGE=37 RECLEN=2920
METHOD L (
* 01 04,
* 05 10,
* 11 11,
* 12 21,
* 22 40,
...)

$ cat old.sql | sed -e 's/--.*//' > new.sql
$ cat new.sql

LOAD CLIENT FROM /path/to/file OF ASC MODIFIED BY BINARYNUMERICS
PACKEDDECIMAL USEDEFAULTS CODEPAGE=37 RECLEN=2920
METHOD L (
* 01 04,
* 05 10,
* 11 11,
* 12 21,
* 22 40,
...)

comet.berkeley aT gmail D0t com
--
---------------------------------------------------------------------
Don't knock President Fillmore. *He kept us out of Vietnam.- Hide quoted text -

- Show quoted text -

Inside the LOAD command......i don't think ..you can put Comments. If
you want to know or see the the Columns....in the LOAD command....you
can try like this

db2 describe table t1

Data type Column
Column name schema Data type name
Length Scale Nulls
------------------------------- --------- -------------------
---------- ----- ------
ID SYSIBM INTEGER
4 0 Yes
NUMBER SYSIBM INTEGER
4 0 Yes

2 record(s) selected.

db2 "load from 1.dat of del method P(1,2) replace into t1(id,number)
nonrecoverable"

If not..the only option is use unix ..as mentioned in the Earlier Post

Cheers...
Shashi Mannepalli

Reply With Quote
  #4  
Old   
Lennart Jonsson
 
Posts: n/a

Default Re: Comments in a LOAD command? - 03-03-2011 , 03:04 AM



On 2011-03-02 16:17, comet wrote:
[...]
Quote:
First of all I recommend the NONRECOVERABLE and REPLACE options for all
loads to keep from filling up log files.

Why would load fill up the logfiles?

Some comments, NONRECOVERABLE is pretty dangerous stuff, and should only
be used if you understand and can live with the risk, COPY YES is safer
and also allows you to load in a HADR env if you have a shared disk.
REPLACE "deletes" all existing data in the table, so if that is not the
intention it should not be used.

/Lennart

[...]

Reply With Quote
  #5  
Old   
ch
 
Posts: n/a

Default Re: Comments in a LOAD command? - 03-31-2011 , 02:34 PM



Quote:
Any clever ideas/hacks out there, outside of a pre-processor to remove the comments before sending them to DB2?
I have just posted a solution based on sed in this thread:

http://groups.google.com/group/alt.c...ae45df87af822#

The sed script posted there eliminates any non nested /* ... */
comments, and finally eliminates any -- line end comments.

Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.