<div dir="ltr">My understanding is that Ur/Web already packages entire page handlers as a single transaction. You don't have to worry about two dml statements in the same page handler being interrupted in between by another thread: all the SQL happens at "the same time" when the page handler finishes. (According to the manual, this is guaranteed by later Postgres versions, but other DBMSs are flaky.)<div><br></div><div>I'm not sure if you have to worry for the purposes of recursive table constraints (which, by the way,can be defined in the database outside of Ur/Web's generated SQL if really necessary).<div><br></div><div>In principle it's probably possible to write combinators to do multiple dmls in one big statement sent to the database, though this would require introducing a few new types to Basis (analogues to [Basis.query]). I don't know if this gives you a performance win, and in the event that it does, one has to balance the gain with the benefit of prepared statements. If you create an insert statement at runtime from a list of rows to insert, you probably end up not using a prepared statement because the compiler doesn't statically know the structure of the statement. (In contrast, if you make a prepared statement from a type-level record using a [Top.folder], then the expansion is done at compile time and I think you're all set.)<div><br></div><div>In the particular chicken-egg case you mention, it seems like you should just have a single table with the union of the fields, but I find it easy to believe that there's some reason somewhere (e.g. working with existing schemas) that one might need to use recursive constraints.</div></div><div class="gmail_extra"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 3, 2017 at 2:42 PM, Marko Schütz Schmuck <span dir="ltr"><<a href="mailto:markoschuetz@googlemail.com" target="_blank">markoschuetz@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>On Mon, 03 Apr 2017 09:57:30 -0400,<br>
Adam Chlipala wrote:<br>
><br>
> I'm not familiar with a standard database feature to allow that mode, but it sounds like you are referencing<br>
> an extra annotation on constraints. Somehow this situation has only come up once in the 10+ years of Ur/<br>
> Web's existence, and it's never been an issue for my own Ur/Web apps.<br>
<br>
</span>AFAIK "DEFERRABLE INITIALLY DEFERRED" is standard SQL, but I agree<br>
that it might not be of much practical relevance.<br>
<br>
What about the other thought: explicitly merging two dml statements<br>
into one transaction (of course stripping the transactions around the<br>
individual dml statements)?<br>
<br>
Best regards,<br>
<br>
Marko<br>
<div><div class="m_-655098103682364858m_7905810092322715898m_4880242500712520047h5"><br>
<br>
> On 04/02/2017 10:10 AM, Marko Schütz Schmuck wrote:<br>
><br>
> On Sun, 02 Apr 2017 09:02:15 -0400,<br>
> Adam Chlipala wrote:<br>
><br>
> Actually, Ur/Web won't even accept those table definitions: no mutually recursive<br>
> definitions yet, w.r.t. constraints. And I haven't thought before about allowing<br>
> temporary breaking of constraints.<br>
><br>
> "Constraints hold after every statement" -> "Constraints hold after<br>
> every transaction"?<br>
><br>
> On 04/02/2017 08:35 AM, Marko Schütz Schmuck wrote:<br>
><br>
> If I have tables<br>
><br>
> table chicken : { Id : int, Egg : int }<br>
> PRIMARY KEY (Id),<br>
> CONSTRAINT egg FOREIGN KEY Egg REFERENCES egg(Id)<br>
><br>
> table egg : { Id : int, Chicken : int }<br>
> PRIMARY KEY (Id),<br>
> CONSTRAINT chicken FOREIGN KEY Chicken REFERENCES chicken(Id)<br>
><br>
> Outside of Ur/Web this would be solved by setting the constraints<br>
> DEFERRABLE INITIALLY DEFERRED and do the INSERTs pairwise inside a<br>
> single transaction.<br>
><br>
> I doubt that there currently is a way to do this in Ur/Web since there<br>
> is neither a way to specify DEFERRABLE INITIALLY DEFERRED nor a way to<br>
> explicitly form transactions.<br>
><br>
> Would it be enough to introduce an operator<br>
><br>
> dml_sequence : dml -> dml -> dml<br>
><br>
> allowing two dml statements to be composed and run in a single<br>
> transaction together with exposing DEFERRABLE INITIALLY DEFERRED at<br>
> the Ur/Web language level?<br>
><br>
> Best regards,<br>
><br>
> Marko<br>
><br>
> _____________________________<wbr>__________________<br>
> Ur mailing list<br>
> <a href="mailto:Ur@impredicative.com" target="_blank">Ur@impredicative.com</a><br>
> <a href="http://www.impredicative.com/cgi-bin/mailman/listinfo/ur" rel="noreferrer" target="_blank">http://www.impredicative.com/<wbr>cgi-bin/mailman/listinfo/ur</a><br>
><br>
> _____________________________<wbr>__________________<br>
> Ur mailing list<br>
> <a href="mailto:Ur@impredicative.com" target="_blank">Ur@impredicative.com</a><br>
> <a href="http://www.impredicative.com/cgi-bin/mailman/listinfo/ur" rel="noreferrer" target="_blank">http://www.impredicative.com/<wbr>cgi-bin/mailman/listinfo/ur</a><br>
><br>
><br>
</div></div>> [2 <text/plain; utf-8 (base64)>]<br>
<div class="m_-655098103682364858m_7905810092322715898m_4880242500712520047HOEnZb"><div class="m_-655098103682364858m_7905810092322715898m_4880242500712520047h5">> ______________________________<wbr>_________________<br>
> Ur mailing list<br>
> <a href="mailto:Ur@impredicative.com" target="_blank">Ur@impredicative.com</a><br>
> <a href="http://www.impredicative.com/cgi-bin/mailman/listinfo/ur" rel="noreferrer" target="_blank">http://www.impredicative.com/c<wbr>gi-bin/mailman/listinfo/ur</a><br>
</div></div><br>______________________________<wbr>_________________<br>
Ur mailing list<br>
<a href="mailto:Ur@impredicative.com" target="_blank">Ur@impredicative.com</a><br>
<a href="http://www.impredicative.com/cgi-bin/mailman/listinfo/ur" rel="noreferrer" target="_blank">http://www.impredicative.com/c<wbr>gi-bin/mailman/listinfo/ur</a><br>
<br></blockquote></div><br></div></div></div>