473,386 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

load in an atomic statement -anyone resolved this??

Begin Atomic
Declare a integer;

Set a=(select count(1) from claims.table1);

if a<>0 then

import into c:\tmptyfile.txt of del replace into claims.table1;
end if;
End!
Commit!

the above returns an error. How do I execute db2 commands inside atomic
statement.
Error is shown as below:

DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0104N An unexpected token "into" was found following "table1);
db2
import". Expected tokens may include: "JOIN". LINE NUMBER=10.
SQLSTATE=42601

Nov 12 '05 #1
5 2153
hi****@gmail.com wrote:
Begin Atomic
Declare a integer;

Set a=(select count(1) from claims.table1);

if a<>0 then

import into c:\tmptyfile.txt of del replace into claims.table1;
end if;
End!
Commit!

the above returns an error. How do I execute db2 commands inside atomic
statement.
Error is shown as below:

DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0104N An unexpected token "into" was found following "table1);
db2
import". Expected tokens may include: "JOIN". LINE NUMBER=10.
SQLSTATE=42601

BEGIN ATOMIC.. END is an SQL statement, not a command. That's why.
Now I'm curious on this construct:
You count all rows just to test whether the table is empty.
It's a bit like counting stars when the question is whether the night is
clear. If you speed this up using an EXISTS then maybe you can drive teh
logic thorugh your app without much problem. You can use a high
isolation level if you want to make sure noone sneaks in a row.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2
Thanks Serge for your tip.

Correction: The import/load into is not into table1(T1) but into
table2(T2). Is there no option from task center or some script to
execute this kind of a logic?

I want to check a table say T1 if it contains records, and if so, then
delete rows in the huge table say T2(I wanted to accomplish this
quicker by load replace with empty file or with "alter table T2
activate not logged initially with empty table"). Then I want to insert
records from T3 to T2.

Serge Rielau wrote:
hi****@gmail.com wrote:
Begin Atomic
Declare a integer;

Set a=(select count(1) from claims.table1);

if a<>0 then

import into c:\tmptyfile.txt of del replace into claims.table1;
end if;
End!
Commit!

the above returns an error. How do I execute db2 commands inside atomic
statement.
Error is shown as below:

DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0104N An unexpected token "into" was found following "table1);
db2
import". Expected tokens may include: "JOIN". LINE NUMBER=10.
SQLSTATE=42601

BEGIN ATOMIC.. END is an SQL statement, not a command. That's why.
Now I'm curious on this construct:
You count all rows just to test whether the table is empty.
It's a bit like counting stars when the question is whether the night is
clear. If you speed this up using an EXISTS then maybe you can drive teh
logic thorugh your app without much problem. You can use a high
isolation level if you want to make sure noone sneaks in a row.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab


Nov 12 '05 #3
hi****@gmail.com wrote:
Thanks Serge for your tip.

Correction: The import/load into is not into table1(T1) but into
table2(T2). Is there no option from task center or some script to
execute this kind of a logic?

I want to check a table say T1 if it contains records, and if so, then
delete rows in the huge table say T2(I wanted to accomplish this
quicker by load replace with empty file or with "alter table T2
activate not logged initially with empty table"). Then I want to insert
records from T3 to T2.

Ah.. so in other words this is already teh nth interation of spinning
your tires in the sand ;-)
Let's back up and start this from scratch:
1. You cannot do DDL (such as ALTER TABLE in a standalone BEGIN ATOMIC)
2. Knowing that you CAN do ALTER TABLE in an SQL Procedure
using dynamic SQL (Is that the missing piece??).

So:

--#SET TERMINATOR @
CREATE PROCEDURE proc()
BEGIN
DECLARE alterstr VARCHAR(1000);
IF EXISTS(SELECT 1 FROM T) THEN
SET alterstr = 'ALTER TABLE S ACTIVATE NOT LOGGED '
||'INITIALLY WITH EMPTY TABLE';
EXECUTE IMMEDIATE alterstr;
INSERT INTO S SELECT * FROM T;
COMMIT;
END IF;
END
@
--#SET TERMINATOR ;

Now if you want to do a LOAD instead of a NOT LOGGED INSERT you will
need to write a C Procedure and use the LAOD API.
Eventually DB2 will support LOAD through the admin procedure....

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #4
import ###into#### c:\tmptyfile.txt of del replace into claims.table1;

it's "from"

Nov 12 '05 #5
Serge Rielau wrote:
Now if you want to do a LOAD instead of a NOT LOGGED INSERT you will
need to write a C Procedure and use the LAOD API.
Eventually DB2 will support LOAD through the admin procedure....


And to make that part easier, have a look at the truncate procedure here:
http://www.ibm.com/developerworks/db...ein/index.html

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

42
by: Shayan | last post by:
Is there a boolean flag that can be set atomically without needing to wrap it in a mutex? This flag will be checked constantly by multiple threads so I don't really want to deal with the overhead...
3
by: Roopa | last post by:
Hi, Can anybody explain me the meanings of - 1. *Sequence Point* in a expression. For ex: arr = i; /* Is undefined cause of non intervening seq point !*/ How does one go about computing the...
10
by: technocrat | last post by:
Hi, I am trying to declare and cursor and thn load from that cursor into another table. Since I have almost 4 million records, I cant do it without the cursor which reduces the time by almost...
6
by: blackstreetcat | last post by:
consider this code : int i; //gobal var Thread1: i=some value; Thread2: if (i==2) dosomething(); else dosomethingelse();
7
by: Joe HM | last post by:
Hello - I was wondering if there is a simple way of ensuring that some statements are executed as an "atomic operation". Here is what I am dealing with in a GUI ... Dim mAppDomain As...
1
by: huyuhui | last post by:
The following is a question of LOAD utility. Question: How does the DB2 enforce table check constraints for data added to table with the LOAD utility? A. With the BUILD phase of LOAD B. With the...
11
by: japhy | last post by:
Is there a way to read a line (a series of characters ending in a newline) from a file (either by descriptor or stream) atomically, without buffering additional contents of the file?
2
by: Freedom fighter | last post by:
Hello, Is a singleton class the same as an atomic class? I know that a singleton class can only be instantiated once, but does that concept apply to an atomic class? Thank you.
5
by: Alex Vinokur | last post by:
void foo (int n) { std::ostringstream oss; oss << "ABCD: " << n << std::endl; std::cout << oss.str() << std::flush; } That function has been invoked in multiprocessing mode.
0
by: kelleram | last post by:
Is the Not Atomic Continue on SQL Exception clause of the Merge statement not supported on DB2 9.5.1 LUW? I can find info on z/OS but it looks like it's N/A for LUW. I'm looking to make my merge...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.