Re: plpgsql - DECLARE - cannot to use %TYPE or %ROWTYPE for composite types
От | Pavel Stehule |
---|---|
Тема | Re: plpgsql - DECLARE - cannot to use %TYPE or %ROWTYPE for composite types |
Дата | |
Msg-id | CAFj8pRCBa+W7AJqJMNbqYdJROx8s3qes4aZZLQb3F8mTR8+ZXg@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: plpgsql - DECLARE - cannot to use %TYPE or %ROWTYPE for composite types (Tom Lane <tgl@sss.pgh.pa.us>) |
Список | pgsql-hackers |
<div dir="ltr"><br /><div class="gmail_extra"><br /><div class="gmail_quote">2016-03-17 0:39 GMT+01:00 Tom Lane <span dir="ltr"><<ahref="mailto:tgl@sss.pgh.pa.us" target="_blank">tgl@sss.pgh.pa.us</a>></span>:<br /><blockquote class="gmail_quote"style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">Jim Nasby <Jim.Nasby@BlueTreble.com>writes:<br /> > On 3/3/16 4:51 AM, Pavel Stehule wrote:<br /> >> CREATE TABLE a(aint);<br /> >> CREATE TABLE b(a a.a%TYPE)<br /> >><br /> >> And the people expecting the living relationbetween table a and table<br /> >> b. So when I do ALTER a.a, then b.a should be changed. What if I drop<br/> >> a.a or drop a?<br /> >><br /> >> So this is reason, why I don't would this feature in SQLside.<br /><br /> > I don't buy that. plpgsql doesn't work that way, so why would this?<br /> > *especially* withthe %TYPE decorator.<br /><br /></span>Yeah. The %TYPE decorator doesn't work like that in the core parser<br /> either:when you use it, the referenced type is determined immediately<br /> and then it's just as if you'd written that typename to begin with.<br /> I do not see a reason for any of these "type operators" to work<br /> differently.<br /><br/> Another analogy that might help make the point is<br /><br /> set search_path = a;<br /> create tablemyschema.tab(f1 mytype);<br /> set search_path = b;<br /><br /> If there are types "mytype" in both schemasa and b, is myschema.tab.f1<br /> now of type b.mytype? No. The meaning of the type reference is<br /> determinedwhen the command executes, and then you're done.<br /></blockquote><br />This is valid for PostgreSQL. I am notsure if it is true in Oracle, if %TYPE means only reference to type, or %TYPE holds reference to original object - andwhen you change the original object, then the function is invalidated.<br /><br /></div><div class="gmail_quote">Using%TYPE with create time only semantic has not big practical benefit. But when %TYPE enforce all lifedependency, then I have guaranteed so change on original object will be propagated to depend object. With all advantagesand disadvantages.<br /><br /></div><div class="gmail_quote">Postgres uses %TYPE in create time only semantic -but it is not big issue in PLpgSQL, because the creation time there is often - every first execution in session.<br /><br/></div><div class="gmail_quote">The usage of %TYPE outer PL/pgSQL is probably only in FK. But nothing similar is instandard, and I don't see a reason, why we should to implement it. In this moment I don't see any important use case.<br/></div><div class="gmail_quote"><br /></div><div class="gmail_quote">Pavel<br /> <br /></div><div class="gmail_quote"><blockquoteclass="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br/> regards, tom lane<br /></blockquote></div><br /></div></div>
В списке pgsql-hackers по дате отправления: