pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tim Cross <theophilusx@gmail.com>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Syntax checking DO blocks and ALTER TABLE statements?
Date: Wed, 17 Feb 2021 10:44:24 +1100
Message-ID: <87im6rpnye.fsf@gmail.com> (raw)
In-Reply-To: <CAKFQuwYW7YkAzg10KGmXudHhJUwVhitrdiutR9GCT3q1vvW8Cw@mail.gmail.com>
References: <ef0b6d3f-e351-2aef-b09d-3f817cf83269@gmail.com>
	<CAKFQuwYTyXCinTZfqjbm3uWR8gZQ-tssStxhAFFu3RQmSPUjDA@mail.gmail.com>
	<87r1lfpp7k.fsf@gmail.com>
	<CAKFQuwYW7YkAzg10KGmXudHhJUwVhitrdiutR9GCT3q1vvW8Cw@mail.gmail.com>


David G. Johnston <david.g.johnston@gmail.com> writes:

> On Tue, Feb 16, 2021 at 4:28 PM Tim Cross <theophilusx@gmail.com> wrote:
>
>>
>> David G. Johnston <david.g.johnston@gmail.com> writes:
>>
>> > On Tue, Feb 16, 2021 at 3:43 PM Ron <ronljohnsonjr@gmail.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.
>

True. However, it never ceases to amaze me how many places don't have
such environments. Far too often, my first task when commencing a new
engagement is to sort out environments and procedures to manage change.

> 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.
>

Given the number, I think I would do the same. A good example of why
being 'lazy' can be a virtue. Faster and easier to write a procedure to
generate dynamic SQL than write out all those alter statements manually
or even write it using a scripting language and ODBC if there is
sufficient variation in the statements to make writing it in plsql
'messy'.

--
Tim Cross





view thread (10+ messages)  latest in thread

Message-ID: <87im6rpnye.fsf@gmail.com>
Permalink:  ../87im6rpnye.fsf@gmail.com/
Also on:    postgresql.org/message-id/87im6rpnye.fsf@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: theophilusx@gmail.com, david.g.johnston@gmail.com
  Subject: Re: Syntax checking DO blocks and ALTER TABLE statements?
  In-Reply-To: <87im6rpnye.fsf@gmail.com>
  References: <ef0b6d3f-e351-2aef-b09d-3f817cf83269@gmail.com> <CAKFQuwYTyXCinTZfqjbm3uWR8gZQ-tssStxhAFFu3RQmSPUjDA@mail.gmail.com> <87r1lfpp7k.fsf@gmail.com> <CAKFQuwYW7YkAzg10KGmXudHhJUwVhitrdiutR9GCT3q1vvW8Cw@mail.gmail.com> <87im6rpnye.fsf@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox