Unix Technical Forum

MERGE syntax error

This is a discussion on MERGE syntax error within the DB2 forums, part of the Database Server Software category; --> The statement: merge into nullid.animals_et_in t1 using is3.animals t2 on t1.sire_assoc=t2.assoc and t1.sire_prefix=t2.prefix and t1.sire_regnum=t2.regnum when matched then update ...


Go Back   Unix Technical Forum > Database Server Software > DB2

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 02:27 AM
Bob Stearns
 
Posts: n/a
Default MERGE syntax error

The statement:

merge into nullid.animals_et_in t1 using is3.animals t2
on t1.sire_assoc=t2.assoc and t1.sire_prefix=t2.prefix and
t1.sire_regnum=t2.regnum
when matched then update set t1.sire_bhid=t2.bhid
when not matched then update set t1.sire_bhid=0
go

gets the error message:

Error: An unexpected token "when not matched then" was found following
"T1.SIRE_BHID=T2.BHID". Expected tokens may include: "<merge_when_spec1>".

which I don't understand. I read the syntax diagrams and explanations
and thought that would be valid syntax. Any explanation or reference
would greatly appreciated. DB2 UDB V8.1.5 under Linux.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 02:27 AM
Gert van der Kooij
 
Posts: n/a
Default Re: MERGE syntax error

In article <9qivd.166$iD3.162@fe05.lga>, Bob Stearns (rstearns1241
@charter.net) says...
> The statement:
>
> merge into nullid.animals_et_in t1 using is3.animals t2
> on t1.sire_assoc=t2.assoc and t1.sire_prefix=t2.prefix and
> t1.sire_regnum=t2.regnum
> when matched then update set t1.sire_bhid=t2.bhid
> when not matched then update set t1.sire_bhid=0
> go
>
> gets the error message:
>
> Error: An unexpected token "when not matched then" was found following
> "T1.SIRE_BHID=T2.BHID". Expected tokens may include: "<merge_when_spec1>".
>
> which I don't understand. I read the syntax diagrams and explanations
> and thought that would be valid syntax. Any explanation or reference
> would greatly appreciated. DB2 UDB V8.1.5 under Linux.
>


You are not allowed to do an insert:

NOT MATCHED
Indicates the operation to be performed on the rows where the ON
search condition is false or unknown. Only INSERT or signal-statement
can be specified after THEN.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 02:28 AM
Serge Rielau
 
Posts: n/a
Default Re: MERGE syntax error

Gert van der Kooij wrote:
> In article <9qivd.166$iD3.162@fe05.lga>, Bob Stearns (rstearns1241
> @charter.net) says...
>
>>The statement:
>>
>>merge into nullid.animals_et_in t1 using is3.animals t2
>> on t1.sire_assoc=t2.assoc and t1.sire_prefix=t2.prefix and
>>t1.sire_regnum=t2.regnum
>> when matched then update set t1.sire_bhid=t2.bhid
>> when not matched then update set t1.sire_bhid=0
>>go
>>
>>gets the error message:
>>
>>Error: An unexpected token "when not matched then" was found following
>>"T1.SIRE_BHID=T2.BHID". Expected tokens may include: "<merge_when_spec1>".
>>
>>which I don't understand. I read the syntax diagrams and explanations
>>and thought that would be valid syntax. Any explanation or reference
>>would greatly appreciated. DB2 UDB V8.1.5 under Linux.
>>

>
>
> You are not allowed to do an insert:
>
> NOT MATCHED
> Indicates the operation to be performed on the rows where the ON
> search condition is false or unknown. Only INSERT or signal-statement
> can be specified after THEN.

... which when one thinks about it is the only option... How could DB2
update a row that it didn't find to begin with?

Cheers
Serge
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-27-2008, 02:28 AM
Bob Stearns
 
Posts: n/a
Default Re: MERGE syntax error

Serge Rielau wrote:
> Gert van der Kooij wrote:
>
>> In article <9qivd.166$iD3.162@fe05.lga>, Bob Stearns (rstearns1241
>> @charter.net) says...
>>
>>> The statement:
>>>
>>> merge into nullid.animals_et_in t1 using is3.animals t2
>>> on t1.sire_assoc=t2.assoc and t1.sire_prefix=t2.prefix and
>>> t1.sire_regnum=t2.regnum
>>> when matched then update set t1.sire_bhid=t2.bhid
>>> when not matched then update set t1.sire_bhid=0
>>> go
>>>
>>> gets the error message:
>>>
>>> Error: An unexpected token "when not matched then" was found
>>> following "T1.SIRE_BHID=T2.BHID". Expected tokens may include:
>>> "<merge_when_spec1>".
>>>
>>> which I don't understand. I read the syntax diagrams and explanations
>>> and thought that would be valid syntax. Any explanation or reference
>>> would greatly appreciated. DB2 UDB V8.1.5 under Linux.
>>>

>>
>>
>> You are not allowed to do an insert:
>>
>> NOT MATCHED
>> Indicates the operation to be performed on the rows where the ON
>> search condition is false or unknown. Only INSERT or signal-statement
>> can be specified after THEN.

>
> .. which when one thinks about it is the only option... How could DB2
> update a row that it didn't find to begin with?
>
> Cheers
> Serge

Doh!! I continue to think of 'not matched' meaning t1 not matched. It is
of course t2 which is not matched. Syntax like 'into not matched' and
'using not matched' (these choices are abominable, but it's late) would
be useful and cover all 3 cases.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-27-2008, 02:28 AM
Serge Rielau
 
Posts: n/a
Default Re: MERGE syntax error

Bob Stearns wrote:
> Serge Rielau wrote:
>
>> Gert van der Kooij wrote:
>>
>>> In article <9qivd.166$iD3.162@fe05.lga>, Bob Stearns (rstearns1241
>>> @charter.net) says...
>>>
>>>> The statement:
>>>>
>>>> merge into nullid.animals_et_in t1 using is3.animals t2
>>>> on t1.sire_assoc=t2.assoc and t1.sire_prefix=t2.prefix and
>>>> t1.sire_regnum=t2.regnum
>>>> when matched then update set t1.sire_bhid=t2.bhid
>>>> when not matched then update set t1.sire_bhid=0
>>>> go
>>>>
>>>> gets the error message:
>>>>
>>>> Error: An unexpected token "when not matched then" was found
>>>> following "T1.SIRE_BHID=T2.BHID". Expected tokens may include:
>>>> "<merge_when_spec1>".
>>>>
>>>> which I don't understand. I read the syntax diagrams and
>>>> explanations and thought that would be valid syntax. Any
>>>> explanation or reference would greatly appreciated. DB2 UDB V8.1.5
>>>> under Linux.
>>>>
>>>
>>>
>>> You are not allowed to do an insert:
>>>
>>> NOT MATCHED
>>> Indicates the operation to be performed on the rows where the ON
>>> search condition is false or unknown. Only INSERT or signal-statement
>>> can be specified after THEN.

>>
>>
>> .. which when one thinks about it is the only option... How could DB2
>> update a row that it didn't find to begin with?
>>
>> Cheers
>> Serge

>
> Doh!! I continue to think of 'not matched' meaning t1 not matched. It is
> of course t2 which is not matched. Syntax like 'into not matched' and
> 'using not matched' (these choices are abominable, but it's late) would
> be useful and cover all 3 cases.

DB2 has an (obvious) extension to the standard allowing you to add
predicates to MATCHED and NOT MATCHED. So you can indeed have more than
one UPDATE, DELETE and/or INSERT clause.
The ON-clause partitiones teh set into MATHCED and NOT MATCHED the
predicates sub-partitioned into the various phases.

Not sure if that covers what you're asking for.
Cheers
Serge
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:09 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com