Thread: dropdb and dropuser: IF EXISTS
I noticed a few places where it would be handy if dropdb took a flag like "--if-exists" which would basically just add in the 'IF EXISTS' clause to the DROP DATABASE statement. For example, scripts like find_static or mbregress.sh use dropdb && createdb, but they generate noisy errors from dropdb when run for the first time since there's no --if-exists flag. (They could just pipe 'DROP DATABASE IF EXISTS ...' to psql, but what's the point of having dropdb if it's not used?) Attached is a very quick patch implementing the "--if-exists" or "-X" option for dropdb and dropuser. I didn't bother adding in a check to make sure the server version was 8.2+ since we're not even supporting 8.1 nowadays, though that'd be easy enough to add in. Josh
Attachment
On Fri, Aug 26, 2011 at 12:08 AM, Josh Kupershmidt <schmiddy@gmail.com> wrote: > I noticed a few places where it would be handy if dropdb took a flag > like "--if-exists" which would basically just add in the 'IF EXISTS' > clause to the DROP DATABASE statement. For example, scripts like > find_static or mbregress.sh use dropdb && createdb, but they generate > noisy errors from dropdb when run for the first time since there's no > --if-exists flag. (They could just pipe 'DROP DATABASE IF EXISTS ...' > to psql, but what's the point of having dropdb if it's not used?) > > Attached is a very quick patch implementing the "--if-exists" or "-X" > option for dropdb and dropuser. I didn't bother adding in a check to > make sure the server version was 8.2+ since we're not even supporting > 8.1 nowadays, though that'd be easy enough to add in. +1 for --if-exists, but -X isn't doing a lot for me, especially since we've used -X for other purposes in other commands. I'd just skip having a short form for this one. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
On Fri, Aug 26, 2011 at 10:42 PM, Robert Haas <robertmhaas@gmail.com> wrote: > +1 for --if-exists, but -X isn't doing a lot for me, especially since > we've used -X for other purposes in other commands. I'd just skip > having a short form for this one. Fine by me. Updated patch attached. Josh
Attachment
On Mon, Aug 29, 2011 at 7:34 PM, Josh Kupershmidt <schmiddy@gmail.com> wrote: > On Fri, Aug 26, 2011 at 10:42 PM, Robert Haas <robertmhaas@gmail.com> wrote: >> +1 for --if-exists, but -X isn't doing a lot for me, especially since >> we've used -X for other purposes in other commands. I'd just skip >> having a short form for this one. > > Fine by me. Updated patch attached. Committed with some edits. I stole the documentation language from the DROP DATABASE and DROP USER pages and just copied it over, instead of saying the same thing in different words. And I rearranged the options handling to be more consistent with what we do elsewhere. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
On Tue, Aug 30, 2011 at 11:14 AM, Robert Haas <robertmhaas@gmail.com> wrote: > Committed with some edits. I stole the documentation language from > the DROP DATABASE and DROP USER pages and just copied it over, instead > of saying the same thing in different words. And I rearranged the > options handling to be more consistent with what we do elsewhere. Thanks. I think you accidentally copied the DROP DATABASE snippet into dropuser.sgml as well. Josh
On Tue, Aug 30, 2011 at 12:44 PM, Josh Kupershmidt <schmiddy@gmail.com> wrote: > On Tue, Aug 30, 2011 at 11:14 AM, Robert Haas <robertmhaas@gmail.com> wrote: >> Committed with some edits. I stole the documentation language from >> the DROP DATABASE and DROP USER pages and just copied it over, instead >> of saying the same thing in different words. And I rearranged the >> options handling to be more consistent with what we do elsewhere. > > Thanks. I think you accidentally copied the DROP DATABASE snippet into > dropuser.sgml as well. D'oh. Fixed. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company