473,405 Members | 2,445 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,405 software developers and data experts.

INSERT data-change operation data retrieval

Hello

I use DB2 UDB V8.1.5. Using embedded SQL (SQLJava), I insert a row
into a table which has some foreign keys and check constraints. The
insert works fine, but if I encapsulate the insert into a SELECT INTO
.... FROM FINAL TABLE and then try to _precompile_ it, I get the
following:

SQL0545N (invalidates check constraint). If I try to put DEFAULT for
the column which the ck_constraint applies on, i get SQL0530N (invalid
foreign key) on another column.

I'd like to use the INSERT statement nested in a SELECT statement to
retrieve the generated primary key.

The failing statement looks like this:
SELECT id
INTO :id
FROM FINAL TABLE (
INSERT INTO mytable(id, val)
VALUES (DEFAULT, :inputhostvar)

)


Thanks for your advice.
Nov 12 '05 #1
3 2641
Can't say much without knowing more of the schema (triggers RI, check
constraints).
Try using NEW TABLE instead of FINAL TABLE.
FINAL TABLE is more restrictive than NEW TABLE sinc eit will not accept
anything that could possible change the table after the initial insert.

If you can come up with a repro script I'll gladly take a closer look.

Cheers
Serge

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2
> Try using NEW TABLE instead of FINAL TABLE.
FINAL TABLE is more restrictive than NEW TABLE sinc eit will not accept
anything that could possible change the table after the initial insert.
I've already tried that but no success. I'v noticed a very strange
thing though: The precompile fails, because it actually inserts a row
into the table! It uses the default values (mostly 0) for the columns,
and that's also the reason why it failed the precompile when i had RI
enabled (the 0 doesn't occur in the parent table). So why does the
SELECT x INTO :x FROM FINAL TABLE ...


construct insert a row? Somewhat scary.
Nov 12 '05 #3
Hmm, I have a very hard time imagining how this would happen, but
nothing is impossible.
It would mean that DB2 half way through compiling the statement decides
to switch into EXECUTE IMMEDIATE mode.
Just for sanities sake: You state you get a -545. I presume you
validated that the constraint specified is indeed related to the target
table. (and not some other object, which soemhow is not happy during
precompilation).
I think the degree of spookyness here is beyond what is likley to be
solved in this newsgroup. You may want to consider calling support.
Have a db2trc handy. That'll be the telltale for what's happening :-)

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #4

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

Similar topics

3
by: Howard Hinnant | last post by:
I recently asked for a survey of multimap insert with hint behavior, in support of a paper I'm writing concerning lwg issue 233. My sincere thanks to Beman Dawes, Raoul Gough, Russell Hind, Bronek...
6
by: Mark P | last post by:
Some time ago I posted here about inserting into a set with a hint: ...
14
by: serge | last post by:
I have a scenario where two tables are in a One-to-Many relationship and I need to move the data from the Many table to the One table so that it becomes a One-to-One relationship. I need to...
2
by: Ford Desperado | last post by:
I've been reading the docs and playing around, but I'm still not getting the difference. For instance, create table a(i int check(i>0)) create table a_src(i int) go create unique index ai on...
11
by: Jean-Christian Imbeault | last post by:
I have a table with a primary field and a few other fields. What is the fastest way to do an insert into that table assuming that sometimes I might try to insert a record with a duplicate primary...
4
by: Chris Kratz | last post by:
Hello all, We have run into what appears to be a problem with rules and subselects in postgres 7.4.1. We have boiled it down to the following test case. If anyone has any thoughts as to why...
20
by: Mark Harrison | last post by:
So I have some data that I want to put into a table. If the row already exists (as defined by the primary key), I would like to update the row. Otherwise, I would like to insert the row. I've...
3
by: MP | last post by:
Hi Posted this several hours ago to another ng but it never showed up thought i'd try here. using vb6, ado, .mdb, jet4.0, no access given table tblJob with field JobNumber text(10) 'The...
0
by: Steven Blair | last post by:
Hi, Would be grateful if anyone with a high understanding of the SqlDataSource and FormView could have a look at my example and my problems. This has really been puzzling me for some time, and...
1
by: abhi81 | last post by:
Hello All, I have a table on which I have created a insert,Update and a Delete trigger. All these triggers write a entry to another audit table with the unique key for each table and the timestamp....
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.