Re: Why does the PL/pgSQL compiler do this?

Поиск
Список
Период
Сортировка
От Michael Moore
Тема Re: Why does the PL/pgSQL compiler do this?
Дата
Msg-id CACpWLjNjuiEp-PnHH=NqXQ=BxX9H4GOnxoQj-9pWuCGP-7YbXQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Why does the PL/pgSQL compiler do this?  (Adrian Klaver <adrian.klaver@aklaver.com>)
Ответы Re: Why does the PL/pgSQL compiler do this?
Список pgsql-sql
<div dir="ltr">Thanks Adrian, but is  ROLLBACK  <b><u>ever</u></b> possible in PL/pgSQL? My understanding is,
"No".</div><divclass="gmail_extra"><br /><div class="gmail_quote">On Mon, Oct 31, 2016 at 4:38 PM, Adrian Klaver <span
dir="ltr"><<ahref="mailto:adrian.klaver@aklaver.com" target="_blank">adrian.klaver@aklaver.com</a>></span>
wrote:<br/><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span
class="">On10/31/2016 04:32 PM, Michael Moore wrote:<br /><blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px#ccc solid;padding-left:1ex"> I'm still a bit confused. If I replace the ROLLBACK; command with<br
/>ELEPHANT; the result is a syntax error. Why doesn't ROLLBACK; produce<br /> the same error since it is not valid in
theLANGUAGE plpgsql.  I<br /> understand that "ROLLBACK TO SAVEPOINT" IS valid. But it's not the same<br /> thing.<br
/></blockquote><br/></span> I am guessing this:<br /><br /><a
href="https://www.postgresql.org/docs/9.5/static/plpgsql-implementation.html"rel="noreferrer"
target="_blank">https://www.postgresql.org/doc<wbr/>s/9.5/static/plpgsql-implement<wbr />ation.html</a><br /> " A
disadvantageis that errors in a specific expression or command cannot be detected until that part of the function is
reachedin execution. (Trivial syntax errors will be detected during the initial parsing pass, but anything deeper will
notbe detected until execution.)"<br /><br /> ROLLBACK might actually be valid at some point, ELEPHANT will not so it
caughtin the trivial error stage.<br /><br /><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px
#cccsolid;padding-left:1ex"><span class=""><br /> On Mon, Oct 31, 2016 at 3:55 PM, Michael Moore <<a
href="mailto:michaeljmoore@gmail.com"target="_blank">michaeljmoore@gmail.com</a><br /></span><span class="">
<mailto:<ahref="mailto:michaeljmoore@gmail.com" target="_blank">michaeljmoore@gmail.co<wbr />m</a>>> wrote:<br
/><br/>     Cool, thanks David, I'll give it a read.<br /><br /><br />     On Mon, Oct 31, 2016 at 3:24 PM, David G.
Johnston<br/></span><span class="">     <<a href="mailto:david.g.johnston@gmail.com"
target="_blank">david.g.johnston@gmail.com</a><mailto:<a href="mailto:david.g.johnston@gmail.com"
target="_blank">david.g.johnston@gmail<wbr/>.com</a>>> wrote:<br /><br />         On Mon, Oct 31, 2016 at 3:13
PM,Michael Moore<br /></span>         <<a href="mailto:michaeljmoore@gmail.com"
target="_blank">michaeljmoore@gmail.com</a><mailto:<a href="mailto:michaeljmoore@gmail.com"
target="_blank">michaeljmoore@gmail.co<wbr/>m</a>>>wrote:<span class=""><br /><br />             Here is the
completefunction, but all you need to look at<br />             is the exception block. (I didn't write this code) :-) 
I<br/>             will ask the question after the code.<br />             ​[...]​<br /><br />                    
RETURNTRUE;<br /><br />             EXCEPTION WHEN OTHERS THEN<br /><br />                     RAISE EXCEPTION '% %',
SQLERRM,SQLSTATE;<br /><br />                     ROLLBACK;<br /><br />                     RETURN FALSE;<br /><br />  
         END;<br /><br />             $BODY$<br /><br />               LANGUAGE plpgsql VOLATILE<br /><br />          
   COST 100;<br /><br /><br />             So, here is the question. Why does the compiler not catch:<br /><br />      
     1) ROLLBACK; is not a valid PL/pgSQL command<br /><br /><br />         R<br />         ​eading section ​41.10.2 at
thelinked page should answer this part.<br /><br />         <a
href="https://www.postgresql.org/docs/current/static/plpgsql-implementation.html"rel="noreferrer"
target="_blank">https://www.postgresql.org/doc<wbr/>s/current/static/plpgsql-imple<wbr />mentation.html</a><br />      
 <<a href="https://www.postgresql.org/docs/current/static/plpgsql-implementation.html" rel="noreferrer"
target="_blank">https://www.postgresql.org/do<wbr/>cs/current/static/plpgsql-impl<wbr />ementation.html</a>><br
/><br/><br />             2) ROLLBACK; and RETURN FALSE; can never be reached<br /><br /><br /><br />         Similar
tothe above - though "static analysis" is yet a step<br />         beyond even what the syntax checking skipping
coveredabove<br />         would reveal.<br /><br />         ​David J.​<br /><br /><br /><br
/></span></blockquote><spanclass="HOEnZb"><font color="#888888"><br /><br /> -- <br /> Adrian Klaver<br /><a
href="mailto:adrian.klaver@aklaver.com"target="_blank">adrian.klaver@aklaver.com</a><br
/></font></span></blockquote></div><br/></div> 

В списке pgsql-sql по дате отправления:

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: Why does the PL/pgSQL compiler do this?
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: Why does the PL/pgSQL compiler do this?