<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: I wish</title>
	<atom:link href="http://jonathanlewis.wordpress.com/2012/01/06/i-wish-5/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonathanlewis.wordpress.com/2012/01/06/i-wish-5/</link>
	<description>Just another Oracle weblog</description>
	<lastBuildDate>Wed, 19 Jun 2013 18:51:29 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: David Penington</title>
		<link>http://jonathanlewis.wordpress.com/2012/01/06/i-wish-5/#comment-56030</link>
		<dc:creator><![CDATA[David Penington]]></dc:creator>
		<pubDate>Mon, 03 Jun 2013 23:01:17 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8040#comment-56030</guid>
		<description><![CDATA[The virtual column is a very nice trick.
My case is the history one, with a current version whose values I want to copy.
Thank you for pointing me to this discussion,]]></description>
		<content:encoded><![CDATA[<p>The virtual column is a very nice trick.<br />
My case is the history one, with a current version whose values I want to copy.<br />
Thank you for pointing me to this discussion,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2012/01/06/i-wish-5/#comment-44677</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Thu, 26 Jan 2012 20:47:33 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8040#comment-44677</guid>
		<description><![CDATA[James,

Nice trick.
Only 11g, of course.]]></description>
		<content:encoded><![CDATA[<p>James,</p>
<p>Nice trick.<br />
Only 11g, of course.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2012/01/06/i-wish-5/#comment-44676</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Thu, 26 Jan 2012 20:47:02 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8040#comment-44676</guid>
		<description><![CDATA[Matthias,
That&#039;s an interesting one.
Easily visible to the human eye that T is key-preserved (it can only produce one row in the join), but not implemented.
It makes me wonder if there are any other variants of a similar nature - i.e. key-preservation logically created by a predicate even though it isn&#039;t implied by the underlying constraints.]]></description>
		<content:encoded><![CDATA[<p>Matthias,<br />
That&#8217;s an interesting one.<br />
Easily visible to the human eye that T is key-preserved (it can only produce one row in the join), but not implemented.<br />
It makes me wonder if there are any other variants of a similar nature &#8211; i.e. key-preservation logically created by a predicate even though it isn&#8217;t implied by the underlying constraints.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2012/01/06/i-wish-5/#comment-44675</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Thu, 26 Jan 2012 20:41:58 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8040#comment-44675</guid>
		<description><![CDATA[Sokrates,
Thanks for the example.
One thought, though - the main reason for liking the updateable join view is that it ought to make the &quot;double&quot; subquery unnecessary, i.e. code like:
[sourcecode]
update t1
set column X = (subquery)
where exists (very similar subquery)
[/sourcecode]]]></description>
		<content:encoded><![CDATA[<p>Sokrates,<br />
Thanks for the example.<br />
One thought, though &#8211; the main reason for liking the updateable join view is that it ought to make the &#8220;double&#8221; subquery unnecessary, i.e. code like:</p>
<pre class="brush: plain; title: ; notranslate">
update t1
set column X = (subquery)
where exists (very similar subquery)
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Su</title>
		<link>http://jonathanlewis.wordpress.com/2012/01/06/i-wish-5/#comment-44324</link>
		<dc:creator><![CDATA[James Su]]></dc:creator>
		<pubDate>Wed, 11 Jan 2012 19:21:14 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8040#comment-44324</guid>
		<description><![CDATA[virtual column:
[sourcecode]
alter table t1 add (id3 as (1));

update 
    ( 
    select 
        t1.val  v1, 
        t2.val  v2 
    from 
        t1,t2 
    where 
        t1.id1 = t2.id1 
    and t1.id2 = t2.id2 
    and t2.id3 = t1.id3 
)   iv 
set 
    iv.v1 = iv.v2 
;
[/sourcecode]
]]></description>
		<content:encoded><![CDATA[<p>virtual column:</p>
<pre class="brush: plain; title: ; notranslate">
alter table t1 add (id3 as (1));

update 
    ( 
    select 
        t1.val  v1, 
        t2.val  v2 
    from 
        t1,t2 
    where 
        t1.id1 = t2.id1 
    and t1.id2 = t2.id2 
    and t2.id3 = t1.id3 
)   iv 
set 
    iv.v1 = iv.v2 
;
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sokrates</title>
		<link>http://jonathanlewis.wordpress.com/2012/01/06/i-wish-5/#comment-44241</link>
		<dc:creator><![CDATA[Sokrates]]></dc:creator>
		<pubDate>Mon, 09 Jan 2012 13:33:33 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8040#comment-44241</guid>
		<description><![CDATA[Jonathan,

here is another very simple case where ORA-01779 is raised unjustifiedly:
[sourcecode]
create table t(
   id int,
   attr varchar2(10),
   constraint t_pk primary key(id)
);   

create table l(
   id int,
   k int,
   s varchar2(10),
   constraint l_pk primary key(id, k),
   constraint l_fk foreign key(id) references t(id)
);   

insert into t(id, attr) values(1, &#039;aaa&#039;);

update
(
   select t.id, t.attr
   from t, l
   where l.id(+)=t.id
   and l.k(+)=1
   and l.id is null
)
set attr = &#039;bbb&#039;;
[/sourcecode]
gives (11.2.0.2) ORA-01779: cannot modify a column which maps to a non key-preserved table

a workaround would be
[sourcecode]
update
(
   select t.id, t.attr
   from t
   where not exists(select null from l where l.id = t.id and l.k=1)
)
set attr = &#039;bbb&#039;
[/sourcecode]
Matthias
]]></description>
		<content:encoded><![CDATA[<p>Jonathan,</p>
<p>here is another very simple case where ORA-01779 is raised unjustifiedly:</p>
<pre class="brush: plain; title: ; notranslate">
create table t(
   id int,
   attr varchar2(10),
   constraint t_pk primary key(id)
);   

create table l(
   id int,
   k int,
   s varchar2(10),
   constraint l_pk primary key(id, k),
   constraint l_fk foreign key(id) references t(id)
);   

insert into t(id, attr) values(1, 'aaa');

update
(
   select t.id, t.attr
   from t, l
   where l.id(+)=t.id
   and l.k(+)=1
   and l.id is null
)
set attr = 'bbb';
</pre>
<p>gives (11.2.0.2) ORA-01779: cannot modify a column which maps to a non key-preserved table</p>
<p>a workaround would be</p>
<pre class="brush: plain; title: ; notranslate">
update
(
   select t.id, t.attr
   from t
   where not exists(select null from l where l.id = t.id and l.k=1)
)
set attr = 'bbb'
</pre>
<p>Matthias</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sokrates</title>
		<link>http://jonathanlewis.wordpress.com/2012/01/06/i-wish-5/#comment-44125</link>
		<dc:creator><![CDATA[Sokrates]]></dc:creator>
		<pubDate>Fri, 06 Jan 2012 20:34:24 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8040#comment-44125</guid>
		<description><![CDATA[[sourcecode]
sokrates@11.2.0.2 &gt; update
  2      (
  3      select
  4          t1.val  v1,
  5          t2.val  v2
  6      from
  7          t1,t2
  8      where
  9          t1.id1 = t2.id1
 10      and t1.id2 = t2.id2
 11      and t2.id3 = 1
 12  )   iv
 13  set
 14      iv.v1 = iv.v2
 15  ;
    iv.v1 = iv.v2
    *
ERROR at line 14:
ORA-01779: cannot modify a column which maps to a non key-preserved table


sokrates@11.2.0.2 &gt; REM so, we do the equivalent
sokrates@11.2.0.2 &gt; update
  2      (
  3      select
  4          t1.val v1,
  5          (select t2.val from t2
  6           where
  7               t1.id1 = t2.id1
  8           and t1.id2 = t2.id2
  9           and t2.id3 = 1
 10          ) v2
 11      from
 12          t1
 13      where (t1.id1, t1.id2) in
 14      (
 15         select t2.id1, t2.id2
 16         from t2
 17         where t2.id3 = 1
 18      )
 19  )   iv
 20  set
 21      iv.v1 = iv.v2
 22  ;

1 row updated.
[/sourcecode]
]]></description>
		<content:encoded><![CDATA[<pre class="brush: plain; title: ; notranslate">
sokrates@11.2.0.2 &gt; update
  2      (
  3      select
  4          t1.val  v1,
  5          t2.val  v2
  6      from
  7          t1,t2
  8      where
  9          t1.id1 = t2.id1
 10      and t1.id2 = t2.id2
 11      and t2.id3 = 1
 12  )   iv
 13  set
 14      iv.v1 = iv.v2
 15  ;
    iv.v1 = iv.v2
    *
ERROR at line 14:
ORA-01779: cannot modify a column which maps to a non key-preserved table


sokrates@11.2.0.2 &gt; REM so, we do the equivalent
sokrates@11.2.0.2 &gt; update
  2      (
  3      select
  4          t1.val v1,
  5          (select t2.val from t2
  6           where
  7               t1.id1 = t2.id1
  8           and t1.id2 = t2.id2
  9           and t2.id3 = 1
 10          ) v2
 11      from
 12          t1
 13      where (t1.id1, t1.id2) in
 14      (
 15         select t2.id1, t2.id2
 16         from t2
 17         where t2.id3 = 1
 18      )
 19  )   iv
 20  set
 21      iv.v1 = iv.v2
 22  ;

1 row updated.
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>
