From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | Tim Cross <theophilusx(at)gmail(dot)com> |
Cc: | "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Syntax checking DO blocks and ALTER TABLE statements? |
Date: | 2021-02-16 23:32:10 |
Message-ID: | CAKFQuwYW7YkAzg10KGmXudHhJUwVhitrdiutR9GCT3q1vvW8Cw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Tue, Feb 16, 2021 at 4:28 PM Tim Cross <theophilusx(at)gmail(dot)com> wrote:
>
> David G. Johnston <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
>
> > On Tue, Feb 16, 2021 at 3:43 PM Ron <ronljohnsonjr(at)gmail(dot)com> wrote:
> >
> >>
> >> How does one go about syntax checking this?
> >>
> >> (There are 222 ALTER TABLE ADD FOREIGN KEY statements that I'm wrapping
> in
> >> similar DO blocks, and want to make sure the statements are clean.)
> >>
> >>
> > Begin a transaction, execute the DO, capture an error if there is one,
> > rollback the transaction.
> >
>
> As David points out, wrapping the whole thing in a transaction will at
> least guarantee it all succeeds or it is all rollled back. This can be
> frustrating if the statements are slow and there are a lot of them as it
> can result in a very tedious do-run-fix cycle.
>
>
I do presume that someone wanting to test their code in this manner would
be doing so in a test environment and an empty database. Which makes the
execution time very small.
I personally would also solve the "lot of them" problem by using dynamic
SQL, so one pretty much only has to test the code generator instead of all
the actual executions - which can simply be confirmed fairly quickly once
on a test database without the need for transactions.
David J.
From | Date | Subject | |
---|---|---|---|
Next Message | Tim Cross | 2021-02-16 23:44:24 | Re: Syntax checking DO blocks and ALTER TABLE statements? |
Previous Message | Tim Cross | 2021-02-16 23:16:14 | Re: Syntax checking DO blocks and ALTER TABLE statements? |