Subject | Re: [firebird-support] Merge in Fb3 fails |
---|---|
Author | Dimitry Sibiryakov |
Post date | 2016-05-15T10:36:18Z |
14.05.2016 22:04, kyleblm@... [firebird-support] wrote:
target. Add grouping to your source query like this:
merge into ZipCodeRef T1
using
(select ZipCode, MAX(Longitude) lo, MAX(Latitude) la
from ZipCodeDataBus
group by 1) as T2
on T2.ZipCode = T1.ZipCode
when not matched then
insert (ZipCode, Longitude, Latitude) values (T2.ZipCode, T2.Lo, T2.La);
--
WBR, SD.
> Above works. Merge below fails:By SQL standard MERGE must fail if several records from source matches single record in
>
> merge into ZipCodeRef T1
> using ZipCodeDataBus T2
> on T2.ZipCode = T1.ZipCode
> when not matched then
> insert (ZipCode, Longitude, Latitude) values (T2.ZipCode, T2.Longitude, T2.Latitude);
target. Add grouping to your source query like this:
merge into ZipCodeRef T1
using
(select ZipCode, MAX(Longitude) lo, MAX(Latitude) la
from ZipCodeDataBus
group by 1) as T2
on T2.ZipCode = T1.ZipCode
when not matched then
insert (ZipCode, Longitude, Latitude) values (T2.ZipCode, T2.Lo, T2.La);
--
WBR, SD.