dbTalk Databases Forums  

correlated update?

comp.databases.ingres comp.databases.ingres


Discuss correlated update? in the comp.databases.ingres forum.



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

Default correlated update? - 03-15-2011 , 03:55 AM






I am trying to do a correlated update (rather rare condition) because
I have unique entries in table 'tylik' which correlate to multiple
entries in table 'mylik', in the sense of overwriting the 'c_typ_g'
value in table 'tylik'

update tylik t
set c_typ_g=
(select c_typ_g from mylik m
where t.c_typ_ylik=m.c_typ_ylik)

but I do get a :

E_US1401 Scalar subqueries not yet supported in this context.
(Tue Mar 15 11:49:07 2011)
End of Request - Terminated by Errors

this means that it will be supported in the future ?

I worked around it by making a procedure which does the overwriting
going row by row but it would be cool if this feature would be
implemented

Reply With Quote
  #2  
Old   
Peter Gale
 
Posts: n/a

Default Re: [Info-Ingres] correlated update? - 03-15-2011 , 04:56 AM






Try this

update tylik t
FROM mylik m
set c_typ_g=m.c_typ_g
where t.c_typ_ylik=m.c_typ_ylik

On 15 March 2011 09:55, nikosv <nikosv01 (AT) gmail (DOT) com> wrote:

Quote:
I am trying to do a correlated update (rather rare condition) because
I have unique entries in table 'tylik' which correlate to multiple
entries in table 'mylik', in the sense of overwriting the 'c_typ_g'
value in table 'tylik'

update tylik t
set c_typ_g=
(select c_typ_g from mylik m
where t.c_typ_ylik=m.c_typ_ylik)

but I do get a :

E_US1401 Scalar subqueries not yet supported in this context.
(Tue Mar 15 11:49:07 2011)
End of Request - Terminated by Errors

this means that it will be supported in the future ?

I worked around it by making a procedure which does the overwriting
going row by row but it would be cool if this feature would be
implemented
_______________________________________________
Info-Ingres mailing list
Info-Ingres (AT) kettleriverconsulting (DOT) com
http://ext-cando.kettleriverconsulti...fo/info-ingres



--
Peter Gale
pgale61 (AT) gmail (DOT) com

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

Default Re: correlated update? - 03-15-2011 , 05:06 AM



On Mar 15, 12:56*pm, Peter Gale <pgal... (AT) gmail (DOT) com> wrote:
Quote:
Try this

update tylik t
FROM mylik m
set c_typ_g=m.c_typ_g
* * *where t.c_typ_ylik=m.c_typ_ylik

On 15 March 2011 09:55, nikosv <nikos... (AT) gmail (DOT) com> wrote:




hi
gives :

E_US125D Ambiguous replace: you have specified several replacements
for
the same row.
(Tue Mar 15 13:05:15 2011)

which is what I am trying to avoid

Reply With Quote
  #4  
Old   
Karl Schendel
 
Posts: n/a

Default Re: [Info-Ingres] correlated update? - 03-15-2011 , 05:23 AM



On Mar 15, 2011, at 7:06 AM, nikosv wrote:

Quote:
On Mar 15, 12:56 pm, Peter Gale <pgal... (AT) gmail (DOT) com> wrote:
Try this

update tylik t
FROM mylik m
set c_typ_g=m.c_typ_g
where t.c_typ_ylik=m.c_typ_ylik

gives :

E_US125D Ambiguous replace: you have specified several replacements
for
the same row.
(Tue Mar 15 13:05:15 2011)

Are the m.c_typ_g's in fact ambiguous? or is there only one
m.c_typ_g value per m.c_typ_ylik, but multiple occurrences?

If the latter, you could try:
declare global temporary table session.upd as
select distinct m.c_typ_g, m.c_typ_ylik
from mylik m
where m.c_typ_ylik in (select c_typ_ylik from tylik)
on commit preserve rows with norecovery;

update tylik t
from session.upd u
set c_typ_g = u.c_typ_g
where t.c_typ_ylik = u.c_typ_ylik;

drop session.upd;

the where-clause on the declare global temporary table is
optional, if most of the mylik table is selected it wouldn't be
worth it.

Karl

Reply With Quote
  #5  
Old   
Ian Kirkham
 
Posts: n/a

Default Re: [Info-Ingres] correlated update? - 03-15-2011 , 06:06 AM



The error message would indicate that you are running an older version
of Ingres.
9.3 onwards supports the scalar subqueries though you would probably
still need to handle the likely problem of non-uniqueness of mylik -
this is why the ambiguous replace messages appear as tylik records would
each be potentially updated multiple times. You need to decide which
mylik records value will be used to update a given tylik. If it is
arbitrary, you could use min or max to single out one value - or if the
correlated m.c_typ_g all happen to be the same then making the
sub-select distinct may help.
Regards,
Ian

-----Original Message-----
From: info-ingres-bounces (AT) kettleriver...ting (DOT) com
[mailto:info-ingres-bounces (AT) kettleriverconsulting (DOT) com] On Behalf Of
nikosv
Sent: 15 March 2011 09:55
To: info-ingres (AT) kettleriverconsulting (DOT) com
Subject: [Info-Ingres] correlated update?

I am trying to do a correlated update (rather rare condition) because
I have unique entries in table 'tylik' which correlate to multiple
entries in table 'mylik', in the sense of overwriting the 'c_typ_g'
value in table 'tylik'

update tylik t
set c_typ_g=
(select c_typ_g from mylik m
where t.c_typ_ylik=m.c_typ_ylik)

but I do get a :

E_US1401 Scalar subqueries not yet supported in this context.
(Tue Mar 15 11:49:07 2011)
End of Request - Terminated by Errors

this means that it will be supported in the future ?

I worked around it by making a procedure which does the overwriting
going row by row but it would be cool if this feature would be
implemented
_______________________________________________
Info-Ingres mailing list
Info-Ingres (AT) kettleriverconsulting (DOT) com
http://ext-cando.kettleriverconsulti...fo/info-ingres

Reply With Quote
  #6  
Old   
nikosv
 
Posts: n/a

Default Re: correlated update? - 03-15-2011 , 06:21 AM



Quote:
Are the m.c_typ_g's in fact ambiguous? *or is there only one
m.c_typ_g value per m.c_typ_ylik, but multiple occurrences?

Are the m.c_typ_g's in fact ambiguous?
yes,for example :


c_ylikoy ¦c_typ_ylikl¦c_typ_g
+----------+--------
+-----------------------------------------------------------
¦1200003503¦12000035¦38727
¦1200003504¦12000035¦13380
¦1200003502¦12000035¦13380
¦1200003505¦12000035¦13380
L----------+--------
+-----------------------------------------------------------

Reply With Quote
  #7  
Old   
nikosv
 
Posts: n/a

Default Re: correlated update? - 03-15-2011 , 06:41 AM



Quote:
The error message would indicate that you are running an older version
of Ingres.
true I am on , II 9.2.0 (int.lnx/118)NPTL

Quote:
9.3 onwards supports the scalar subqueries though you would probably
still need to handle the likely problem of non-uniqueness of mylik -
this is why the ambiguous replace messages appear as tylik records would
each be potentially updated multiple times. You need to decide which
mylik records value will be used to update a given tylik.
the requirements are relaxed so any value will work.I do not care what
value gets there in the end hence I don't mind it being overwriten

thanks

Reply With Quote
  #8  
Old   
Karl Schendel
 
Posts: n/a

Default Re: [Info-Ingres] correlated update? - 03-15-2011 , 06:42 AM



On Mar 15, 2011, at 8:21 AM, nikosv wrote:

Quote:
Are the m.c_typ_g's in fact ambiguous? or is there only one
m.c_typ_g value per m.c_typ_ylik, but multiple occurrences?

Are the m.c_typ_g's in fact ambiguous?

yes,for example :


c_ylikoy ¦c_typ_ylikl¦c_typ_g
+----------+--------
+-----------------------------------------------------------
¦1200003503¦12000035¦38727
¦1200003504¦12000035¦13380
¦1200003502¦12000035¦13380
¦1200003505¦12000035¦13380
L----------+--------
+-----------------------------------------------------------
So what you are trying to do is ill-defined anyway.

You can still use the temp table intermediate, but
you'll have to select some c_typ_g (e.g. min or max)
for each c_typ_ylik.

Karl

Reply With Quote
  #9  
Old   
nikosv
 
Posts: n/a

Default Re: correlated update? - 03-15-2011 , 10:31 AM



Quote:
So what you are trying to do is ill-defined anyway.
that is very true but it is done deliberately

Quote:
You can still use the temp table intermediate, but
you'll have to select some c_typ_g (e.g. min or max)
for each c_typ_ylik.

Karl
thanks for the hints
from the discusion, I also found out that the correlated update works
on greater versions; very usefull to know

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.