Re: [PATCHES] drop if exists remnainder (reprise)

2006-06-16 Thread Andrew Dunstan



Andrew Dunstan wrote:



Here is an updated patch for the remaining cases of DROP objtype IF 
EXISTS ... as recently discussed on -hackers.


The cases are:

 language, tablespace, trigger, rule, opclass, function, aggregate. 
operator, and cast.


Regression tests and docs still to come.

I wasn't quite sure how to format the message in the case of aggregate 
- the change in calls there seems to have made it somewhat harder, so 
some advice would be appreciated.





I have committed this to avoid further bitrot.

I will get docs and regression tests done shortly.

cheers

andrew

---(end of broadcast)---
TIP 6: explain analyze is your friend


[PATCHES] drop if exists remnainder (reprise)

2006-06-10 Thread Andrew Dunstan


Here is an updated patch for the remaining cases of DROP objtype IF 
EXISTS ... as recently discussed on -hackers.


The cases are:

 language, tablespace, trigger, rule, opclass, function, aggregate. 
operator, and cast.


Regression tests and docs still to come.

I wasn't quite sure how to format the message in the case of aggregate - 
the change in calls there seems to have made it somewhat harder, so some 
advice would be appreciated.


cheers

andrew




Index: src/backend/commands/aggregatecmds.c
===
RCS file: /cvsroot/pgsql/src/backend/commands/aggregatecmds.c,v
retrieving revision 1.34
diff -c -r1.34 aggregatecmds.c
*** src/backend/commands/aggregatecmds.c	15 Apr 2006 17:45:33 -	1.34
--- src/backend/commands/aggregatecmds.c	10 Jun 2006 14:04:54 -
***
*** 211,217 
  	ObjectAddress object;
  
  	/* Look up function and make sure it's an aggregate */
! 	procOid = LookupAggNameTypeNames(aggName, aggArgs, false);
  
  	/*
  	 * Find the function tuple, do permissions and validity checks
--- 211,231 
  	ObjectAddress object;
  
  	/* Look up function and make sure it's an aggregate */
! 	procOid = LookupAggNameTypeNames(aggName, aggArgs, stmt-missing_ok);
! 	
! 	if (!OidIsValid(procOid))
! 	{
! 		/* we only get here if stmt-missing_ok is true */
! 
! 		/* XXX might need better message here */
! 
! 		ereport(NOTICE,
! (errmsg(aggregate %s does not exist ... skipping,
! 	   stmt-name)));
! 		
! 
! 		return;
! 	}
  
  	/*
  	 * Find the function tuple, do permissions and validity checks
Index: src/backend/commands/functioncmds.c
===
RCS file: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v
retrieving revision 1.74
diff -c -r1.74 functioncmds.c
*** src/backend/commands/functioncmds.c	15 Apr 2006 17:45:34 -	1.74
--- src/backend/commands/functioncmds.c	10 Jun 2006 14:04:56 -
***
*** 687,693 
  	/*
  	 * Find the function, do permissions and validity checks
  	 */
! 	funcOid = LookupFuncNameTypeNames(functionName, argTypes, false);
  
  	tup = SearchSysCache(PROCOID,
  		 ObjectIdGetDatum(funcOid),
--- 687,702 
  	/*
  	 * Find the function, do permissions and validity checks
  	 */
! 	funcOid = LookupFuncNameTypeNames(functionName, argTypes, stmt-missing_ok);
! 	if (stmt-missing_ok !OidIsValid(funcOid)) 
! 	{
! 		ereport(NOTICE,
! (errmsg(function %s(%s) does not exist ... skipping,
! 		NameListToString(functionName),
! 		NameListToString(argTypes;
! 		return;
! 	}
! 
  
  	tup = SearchSysCache(PROCOID,
  		 ObjectIdGetDatum(funcOid),
***
*** 1377,1382 
--- 1386,1392 
  	HeapTuple	tuple;
  	ObjectAddress object;
  
+ 	/* when dropping a cast, the types must exist even if you use IF EXISTS */
  	sourcetypeid = typenameTypeId(NULL, stmt-sourcetype);
  	targettypeid = typenameTypeId(NULL, stmt-targettype);
  
***
*** 1385,1395 
  		   ObjectIdGetDatum(targettypeid),
  		   0, 0);
  	if (!HeapTupleIsValid(tuple))
! 		ereport(ERROR,
! (errcode(ERRCODE_UNDEFINED_OBJECT),
!  errmsg(cast from type %s to type %s does not exist,
! 		TypeNameToString(stmt-sourcetype),
! 		TypeNameToString(stmt-targettype;
  
  	/* Permission check */
  	if (!pg_type_ownercheck(sourcetypeid, GetUserId())
--- 1395,1417 
  		   ObjectIdGetDatum(targettypeid),
  		   0, 0);
  	if (!HeapTupleIsValid(tuple))
! 	{
! 		if (! stmt-missing_ok)
! 			ereport(ERROR,
! 	(errcode(ERRCODE_UNDEFINED_OBJECT),
! 	 errmsg(cast from type %s to type %s does not exist,
! 			TypeNameToString(stmt-sourcetype),
! 			TypeNameToString(stmt-targettype;
! 		else
! 			ereport(NOTICE,
! 	 (errmsg(cast from type %s to type %s does not exist ... skipping,
! 			TypeNameToString(stmt-sourcetype),
! 			TypeNameToString(stmt-targettype;
! 
! 		return;
! 	}
! 
! 			
  
  	/* Permission check */
  	if (!pg_type_ownercheck(sourcetypeid, GetUserId())
Index: src/backend/commands/opclasscmds.c
===
RCS file: /cvsroot/pgsql/src/backend/commands/opclasscmds.c,v
retrieving revision 1.45
diff -c -r1.45 opclasscmds.c
*** src/backend/commands/opclasscmds.c	2 May 2006 22:25:10 -	1.45
--- src/backend/commands/opclasscmds.c	10 Jun 2006 14:04:56 -
***
*** 700,720 
  		/* Unqualified opclass name, so search the search path */
  		opcID = OpclassnameGetOpcid(amID, opcname);
  		if (!OidIsValid(opcID))
! 			ereport(ERROR,
! 	(errcode(ERRCODE_UNDEFINED_OBJECT),
! 	 errmsg(operator class \%s\ does not exist for access method \%s\,
! 			opcname, stmt-amname)));
  		tuple = SearchSysCache(CLAOID,
  			   ObjectIdGetDatum(opcID),
  			   0, 0, 0);
  	}
  
  	if (!HeapTupleIsValid(tuple))
! 		ereport(ERROR,
! (errcode(ERRCODE_UNDEFINED_OBJECT),
!  

Re: [HACKERS] [PATCHES] drop if exists remainder

2006-06-08 Thread Andrew Dunstan

Josh Berkus wrote:

Tom,

  

What's the consensus on this? Nobody else has chimed in, so I'm
inclined to do no more on the gounds of insufficient demand. Let's
decide before too much bitrot occurs, though.


+1 :)
  

+1



We were talking about this on IRC, and I feel that if we're going to do IF 
EXISTS for any objects, we should do it for all objects.  Otherwise we 
risk a considerable amount of user confusion.


  


OK there does seem to be some demand for this, so I will rework the 
patch, and hope to get it done by feature freeze - it has bitrotted with 
7 merge conflicts, including the grammar file, so I need to look 
carefully at that. Pity people didn't speak up when this was first 
raised. :-)


cheers

andrew

---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


Re: [HACKERS] [PATCHES] drop if exists remainder

2006-06-08 Thread David Fetter
On Thu, Jun 08, 2006 at 09:43:19AM -0400, Andrew Dunstan wrote:
 OK there does seem to be some demand for this, so I will rework the
 patch, and hope to get it done by feature freeze - it has bitrotted
 with 7 merge conflicts, including the grammar file, so I need to
 look carefully at that.  Pity people didn't speak up when this was
 first raised. :-)

I did :)

Cheers,
D
-- 
David Fetter [EMAIL PROTECTED] http://fetter.org/
phone: +1 415 235 3778AIM: dfetter666
  Skype: davidfetter

Remember to vote!

---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
   subscribe-nomail command to [EMAIL PROTECTED] so that your
   message can get through to the mailing list cleanly


Re: [HACKERS] [PATCHES] drop if exists remainder

2006-06-08 Thread Andrew Dunstan

David Fetter wrote:

On Thu, Jun 08, 2006 at 09:43:19AM -0400, Andrew Dunstan wrote:
  

OK there does seem to be some demand for this, so I will rework the
patch, and hope to get it done by feature freeze - it has bitrotted
with 7 merge conflicts, including the grammar file, so I need to
look carefully at that.  Pity people didn't speak up when this was
first raised. :-)



I did :)

  



Important as you are, one swallow does not make a summer.

cheers

andrew

---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings


Re: [HACKERS] [PATCHES] drop if exists remainder

2006-06-08 Thread Jim C. Nasby
On Thu, Jun 08, 2006 at 12:34:54PM -0400, Andrew Dunstan wrote:
 David Fetter wrote:
 On Thu, Jun 08, 2006 at 09:43:19AM -0400, Andrew Dunstan wrote:
   
 OK there does seem to be some demand for this, so I will rework the
 patch, and hope to get it done by feature freeze - it has bitrotted
 with 7 merge conflicts, including the grammar file, so I need to
 look carefully at that.  Pity people didn't speak up when this was
 first raised. :-)
 
 
 I did :)
 
   
 
 
 Important as you are, one swallow does not make a summer.

On the other hand, unless we want the lists filling up with a bunch of
+1 posts, it's probably better to assume that unless someone objects a
patch would be accepted.
-- 
Jim C. Nasby, Sr. Engineering Consultant  [EMAIL PROTECTED]
Pervasive Software  http://pervasive.comwork: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf   cell: 512-569-9461

---(end of broadcast)---
TIP 4: Have you searched our list archives?

   http://archives.postgresql.org


Re: [HACKERS] [PATCHES] drop if exists remainder

2006-06-08 Thread Andrew Dunstan

Jim C. Nasby wrote:




Important as you are, one swallow does not make a summer.



On the other hand, unless we want the lists filling up with a bunch of
+1 posts, it's probably better to assume that unless someone objects a
patch would be accepted.
  


What happened was that Tom objected to (or at least queried the need 
for) the patch on the grounds that it was bloat that nobody had asked 
for. And when I asked I wasn't exactly deluged with requests to commit, 
so I concluded that it was not generally wanted. Since then I have had 
probably 10 requests for it, so I am now going to work to update it and 
will post a revised patch.


cheers

andrew


---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


Re: [PATCHES] drop if exists remainder

2006-06-07 Thread Robert Treat
On Saturday 04 March 2006 22:24, David Fetter wrote:
 On Fri, Mar 03, 2006 at 03:35:24PM -0500, Andrew Dunstan wrote:
  Bruce Momjian wrote:
  Christopher Kings-Lynne wrote:
 
  What's the consensus on this? Nobody else has chimed in, so I'm inclined
  to do no more on the gounds of insufficient demand. Let's decide before
  too much bitrot occurs, though.

 +1 :)


+1 

-- 
Robert Treat
Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL

---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


Re: [HACKERS] [PATCHES] drop if exists remainder

2006-06-07 Thread Josh Berkus
Tom,

   What's the consensus on this? Nobody else has chimed in, so I'm
   inclined to do no more on the gounds of insufficient demand. Let's
   decide before too much bitrot occurs, though.
 
  +1 :)

 +1

We were talking about this on IRC, and I feel that if we're going to do IF 
EXISTS for any objects, we should do it for all objects.  Otherwise we 
risk a considerable amount of user confusion.

-- 
--Josh

Josh Berkus
PostgreSQL @ Sun
San Francisco

---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


Re: [PATCHES] drop if exists remainder

2006-03-04 Thread David Fetter
On Fri, Mar 03, 2006 at 03:35:24PM -0500, Andrew Dunstan wrote:
 Bruce Momjian wrote:
 
 Christopher Kings-Lynne wrote:
  
 
 What's the consensus on this? Nobody else has chimed in, so I'm inclined 
 to do no more on the gounds of insufficient demand. Let's decide before 
 too much bitrot occurs, though.

+1 :)

Cheers,
D
-- 
David Fetter [EMAIL PROTECTED] http://fetter.org/
phone: +1 415 235 3778

Remember to vote!

---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
   choose an index scan if your joining column's datatypes do not
   match


Re: [PATCHES] drop if exists remainder

2006-03-03 Thread Andrew Dunstan

Bruce Momjian wrote:


Christopher Kings-Lynne wrote:
 

Here's a first draft patch for DROP ... IF EXISTS for the remaining 
cases, namely: LANGUAGE, TABLESPACE, TRIGGER OPERATOR CLASS, 
FUNCTION, AGGREGATE, OPERATOR, CAST and RULE.
 
 


At what point does this stop being useful and become mere bloat?
The only case I can ever recall being actually asked for was the
TABLE case ...
   

Chris KL said it should be done for all on the grounds of consistency. 
But I will happily stop right now if that's not the general view - I'm 
only doing this to complete something I started.
 

Well, my use-case was to be able to wrap pg_dump -c output in 
begin/commit tags and being able to run and re-run such dumps without 
errors.  Basically I don't like 'acceptable errors' when restoring dumps 
:)  They just confuse newer users especially.


I also just like consistency :)
   



Makes sense.

 



What's the consensus on this? Nobody else has chimed in, so I'm inclined 
to do no more on the gounds of insufficient demand. Let's decide before 
too much bitrot occurs, though.


cheers

andrew

---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

  http://www.postgresql.org/docs/faq


Re: [PATCHES] drop if exists remainder

2006-03-03 Thread Bruce Momjian
Andrew Dunstan wrote:
 Chris KL said it should be done for all on the grounds of consistency. 
 But I will happily stop right now if that's not the general view - I'm 
 only doing this to complete something I started.
   
 
 Well, my use-case was to be able to wrap pg_dump -c output in 
 begin/commit tags and being able to run and re-run such dumps without 
 errors.  Basically I don't like 'acceptable errors' when restoring dumps 
 :)  They just confuse newer users especially.
 
 I also just like consistency :)
 
 
 
 Makes sense.
 
   
 
 
 What's the consensus on this? Nobody else has chimed in, so I'm inclined 
 to do no more on the gounds of insufficient demand. Let's decide before 
 too much bitrot occurs, though.

I kind of liked it, but I think I was the only one.

-- 
  Bruce Momjian   http://candle.pha.pa.us
  SRA OSS, Inc.   http://www.sraoss.com

  + If your life is a hard drive, Christ can be your backup. +

---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
   choose an index scan if your joining column's datatypes do not
   match


Re: [PATCHES] drop if exists remainder

2006-02-06 Thread Christopher Kings-Lynne
Here's a first draft patch for DROP ... IF EXISTS for the remaining 
cases, namely: LANGUAGE, TABLESPACE, TRIGGER OPERATOR CLASS, 
FUNCTION, AGGREGATE, OPERATOR, CAST and RULE.
  


At what point does this stop being useful and become mere bloat?
The only case I can ever recall being actually asked for was the
TABLE case ...


Chris KL said it should be done for all on the grounds of consistency. 
But I will happily stop right now if that's not the general view - I'm 
only doing this to complete something I started.


Well, my use-case was to be able to wrap pg_dump -c output in 
begin/commit tags and being able to run and re-run such dumps without 
errors.  Basically I don't like 'acceptable errors' when restoring dumps 
:)  They just confuse newer users especially.


I also just like consistency :)

Chris


---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

  http://www.postgresql.org/docs/faq


Re: [PATCHES] drop if exists remainder

2006-02-06 Thread Bruce Momjian
Christopher Kings-Lynne wrote:
  Here's a first draft patch for DROP ... IF EXISTS for the remaining 
  cases, namely: LANGUAGE, TABLESPACE, TRIGGER OPERATOR CLASS, 
  FUNCTION, AGGREGATE, OPERATOR, CAST and RULE.

 
  At what point does this stop being useful and become mere bloat?
  The only case I can ever recall being actually asked for was the
  TABLE case ...
  
  Chris KL said it should be done for all on the grounds of consistency. 
  But I will happily stop right now if that's not the general view - I'm 
  only doing this to complete something I started.
 
 Well, my use-case was to be able to wrap pg_dump -c output in 
 begin/commit tags and being able to run and re-run such dumps without 
 errors.  Basically I don't like 'acceptable errors' when restoring dumps 
 :)  They just confuse newer users especially.
 
 I also just like consistency :)

Makes sense.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  pgman@candle.pha.pa.us   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
   choose an index scan if your joining column's datatypes do not
   match


Re: [PATCHES] drop if exists remainder

2006-02-05 Thread Tom Lane
Andrew Dunstan [EMAIL PROTECTED] writes:
 Here's a first draft patch for DROP ... IF EXISTS for the remaining 
 cases, namely: LANGUAGE, TABLESPACE, TRIGGER OPERATOR CLASS, FUNCTION, 
 AGGREGATE, OPERATOR, CAST and RULE.

At what point does this stop being useful and become mere bloat?
The only case I can ever recall being actually asked for was the
TABLE case ...

regards, tom lane

---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
   subscribe-nomail command to [EMAIL PROTECTED] so that your
   message can get through to the mailing list cleanly


Re: [PATCHES] drop if exists remainder

2006-02-05 Thread Andrew Dunstan



Tom Lane wrote:


Andrew Dunstan [EMAIL PROTECTED] writes:
 

Here's a first draft patch for DROP ... IF EXISTS for the remaining 
cases, namely: LANGUAGE, TABLESPACE, TRIGGER OPERATOR CLASS, FUNCTION, 
AGGREGATE, OPERATOR, CAST and RULE.
   



At what point does this stop being useful and become mere bloat?
The only case I can ever recall being actually asked for was the
TABLE case ...


 



Chris KL said it should be done for all on the grounds of consistency. 
But I will happily stop right now if that's not the general view - I'm 
only doing this to complete something I started.


cheers

andrew


---(end of broadcast)---
TIP 4: Have you searched our list archives?

  http://archives.postgresql.org


Re: [PATCHES] drop if exists remainder

2006-02-05 Thread Bruce Momjian
Andrew Dunstan wrote:
 
 
 Tom Lane wrote:
 
 Andrew Dunstan [EMAIL PROTECTED] writes:
   
 
 Here's a first draft patch for DROP ... IF EXISTS for the remaining 
 cases, namely: LANGUAGE, TABLESPACE, TRIGGER OPERATOR CLASS, FUNCTION, 
 AGGREGATE, OPERATOR, CAST and RULE.
 
 
 
 At what point does this stop being useful and become mere bloat?
 The only case I can ever recall being actually asked for was the
 TABLE case ...
 
 
   
 
 
 Chris KL said it should be done for all on the grounds of consistency. 
 But I will happily stop right now if that's not the general view - I'm 
 only doing this to complete something I started.

I am thinking we should have IF EXISTS support for every object that has
CREATE OR REPLACE functionality, plus objects that have storage like
table and perhaps index.

However, I see CREATE ROLE doesn't have REPLACE functionality, so what
is the logic of when we need IF EXISTS and when we don't?  Perhaps they
all should have it, and the REPLACE is just for objects you want to
replace but keep existing linkage in place.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  pgman@candle.pha.pa.us   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


Re: [PATCHES] drop if exists remainder

2006-02-05 Thread Andrew Dunstan



Bruce Momjian wrote:


However, I see CREATE ROLE doesn't have REPLACE functionality, so what
is the logic of when we need IF EXISTS and when we don't?  Perhaps they
all should have it, and the REPLACE is just for objects you want to
replace but keep existing linkage in place.

 



That was my understanding. I think these are orthogonal issues.

Another issue was MySQL compatibility. AFAIK we achieved that when we 
did database, following
{ table view index sequence schema type domain conversion}, which pretty 
much all had to be done together, as they share the same statement node 
type.


cheers

andrew

---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings


Re: [PATCHES] drop if exists - first piece

2005-11-19 Thread Andrew Dunstan



Tom Lane wrote:


New test seems reasonable.
 



done.


A few other minor comments:

* The NOTICEs should probably not carry an ERRCODE; usually you just
want a notice to go out with the default not an error SQLSTATE.
 



done.


* The Assert(missing_ok)s are a waste of code space --- if
ereport(ERROR) ever returned, there would be vast swaths of the backend
that fail, so there's no point in asserting it only here.  They also
make the reader stop to wonder why they are there, which is probably a
bigger objection.
 



done, but I left one with a modified test to reflect what we are really 
testing, i.e. that we didn't fall of the end of a message table.



* It's probably not a good idea to assume that IF is a safe name for
a parser symbol --- too much risk of collision with other macros.
I'd suggest IF_P.
 



done.

Thanks for the review.

Committed as above. I will probably do DROP DATABASE IF EXISTS shortly, 
but anyone who wants to jump in on others is welcome to.


cheers

andrew

---(end of broadcast)---
TIP 4: Have you searched our list archives?

  http://archives.postgresql.org


Re: [PATCHES] drop if exists - first piece

2005-11-18 Thread Tom Lane
Andrew Dunstan [EMAIL PROTECTED] writes:
 I will apply the attached patch tomorrow, barring objection. This covers 
 drop if exists for the following objects:
   table view index sequence schema type domain conversion

 I have a simple test script as show below, but I am not sure where to 
 put it in the regression tests - add a new one maybe?

New test seems reasonable.

A few other minor comments:

* The NOTICEs should probably not carry an ERRCODE; usually you just
want a notice to go out with the default not an error SQLSTATE.

* The Assert(missing_ok)s are a waste of code space --- if
ereport(ERROR) ever returned, there would be vast swaths of the backend
that fail, so there's no point in asserting it only here.  They also
make the reader stop to wonder why they are there, which is probably a
bigger objection.

* It's probably not a good idea to assume that IF is a safe name for
a parser symbol --- too much risk of collision with other macros.
I'd suggest IF_P.

regards, tom lane

---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


Re: [PATCHES] drop if exists

2005-11-17 Thread Andrew Dunstan



Christopher Kings-Lynne wrote:


I think anything else will have to be done individually, although the
pattern can be copied.

Perhaps we should take bids on what should/should not be covered.



Everything should be covered, otherwise it's just annoying for users...



Well, that's arguably more than I originally signed up for ;-) See

http://archives.postgresql.org/pgsql-hackers/2005-10/msg00632.php

There are currently DROP commends for the following 21 objects 
(according to the docs).


AGGREGATE
CAST
CONVERSION
DATABASE
DOMAIN
FUNCTION
GROUP
INDEX
LANGUAGE
OPERATOR
OPERATOR CLASS
ROLE
RULE
SCHEMA
SEQUENCE
TABLE
TABLESPACE
TRIGGER
TYPE
USER
VIEW

If the consensus is to add this to all of them, then I propose to apply 
the patch I have (with a slight fix for an oversight in the case of 
domains, plus docs and tests) for the 8 cases and start working on the 
remaining 13 as time permits. To be honest, I have not even looked at 
those 13 cases.


One motivation for this, besides general utility, is to ease MySQL 
migrations, btw, and AFAICT they only have three DROP commands and only 
two of them (TABLE and DATABASE) have IF EXISTS - DROP INDEX does not 
for some reason - probably because it is actually mapped to an ALTER 
TABLE statement.


cheers

andrew



---(end of broadcast)---
TIP 6: explain analyze is your friend


Re: [PATCHES] drop if exists

2005-11-17 Thread Michael Glaesemann


On Nov 17, 2005, at 11:51 , Christopher Kings-Lynne wrote:


Including objects that already have CREATE OR REPLACE?


I assume so - CREATE OR REPLACE doesn't drop things - only creates  
or replaces them.


Of course. Silly me :)

Michael Glaesemann
grzm myrealbox com




---(end of broadcast)---
TIP 4: Have you searched our list archives?

  http://archives.postgresql.org


Re: [PATCHES] drop if exists

2005-11-17 Thread Christopher Kings-Lynne
If the consensus is to add this to all of them, then I propose to apply 
the patch I have (with a slight fix for an oversight in the case of 
domains, plus docs and tests) for the 8 cases and start working on the 
remaining 13 as time permits. To be honest, I have not even looked at 
those 13 cases.


I agree.  I can have a crack at the others as well.  It's in my area of 
ability I hope ;)  (Except grammar janking)


Chris


---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


Re: [PATCHES] drop if exists

2005-11-16 Thread Bruce Momjian

Removed from queue.  Andrew is committing it.

---

Andrew Dunstan wrote:
 
 OK, now it looks like this:
 
 andrew=# drop table blurflx;
 ERROR:  table blurflx does not exist
 andrew=# drop table if exists blurflx;
 NOTICE:  table blurflx does not exist, skipping
 DROP TABLE
 andrew=# create table blurflx ( x text);
 CREATE TABLE
 andrew=# drop table if exists blurflx;
 DROP TABLE
 andrew=# drop table blurflx;
 ERROR:  table blurflx does not exist
 andrew=#
 
 revised patch attached.
 
 cheers
 
 andrew
 
 Tom Lane wrote:
 
 Andrew Dunstan [EMAIL PROTECTED] writes:
   
 
 andrew=# drop table blurflx;
 ERROR:  table blurflx does not exist
 andrew=# drop table if exists blurflx;
 DROP TABLE
 
 
 
 If I read MySQL's documentation correctly, they emit a NOTE (equivalent
 of a NOTICE message I suppose) when IF EXISTS does nothing because the
 table doesn't exist.  Seems like we should do likewise --- your second
 example here seems actively misleading.  That is, I'd rather see
 
 andrew=# drop table if exists blurflx;
 NOTICE:  table blurflx does not exist, skipping
 DROP TABLE
 
 
  regards, tom lane
 
   
 


 
 ---(end of broadcast)---
 TIP 4: Have you searched our list archives?
 
http://archives.postgresql.org

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  pgman@candle.pha.pa.us   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 4: Have you searched our list archives?

   http://archives.postgresql.org


Re: [PATCHES] drop if exists

2005-11-16 Thread Christopher Kings-Lynne

Will we get this functionality for ALL objects?

Bruce Momjian wrote:

Removed from queue.  Andrew is committing it.

---

Andrew Dunstan wrote:


OK, now it looks like this:

andrew=# drop table blurflx;
ERROR:  table blurflx does not exist
andrew=# drop table if exists blurflx;
NOTICE:  table blurflx does not exist, skipping
DROP TABLE
andrew=# create table blurflx ( x text);
CREATE TABLE
andrew=# drop table if exists blurflx;
DROP TABLE
andrew=# drop table blurflx;
ERROR:  table blurflx does not exist
andrew=#

revised patch attached.

cheers

andrew

Tom Lane wrote:



Andrew Dunstan [EMAIL PROTECTED] writes:




andrew=# drop table blurflx;
ERROR:  table blurflx does not exist
andrew=# drop table if exists blurflx;
DROP TABLE
  



If I read MySQL's documentation correctly, they emit a NOTE (equivalent
of a NOTICE message I suppose) when IF EXISTS does nothing because the
table doesn't exist.  Seems like we should do likewise --- your second
example here seems actively misleading.  That is, I'd rather see

andrew=# drop table if exists blurflx;
NOTICE:  table blurflx does not exist, skipping
DROP TABLE


regards, tom lane








---(end of broadcast)---
TIP 4: Have you searched our list archives?

  http://archives.postgresql.org






---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


Re: [PATCHES] drop if exists

2005-11-16 Thread Andrew Dunstan
Christopher Kings-Lynne said:
 Will we get this functionality for ALL objects?


The patch does these: table, view, index, sequence, schema, type, domain,
and conversion. The reason is that these are all dealt with using the same
bit of the grammar, and the first 4 are pretty much completely done by the
same code.

I think anything else will have to be done individually, although the
pattern can be copied.

Perhaps we should take bids on what should/should not be covered.

cheers

andrew




---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
   subscribe-nomail command to [EMAIL PROTECTED] so that your
   message can get through to the mailing list cleanly


Re: [PATCHES] drop if exists

2005-11-16 Thread Christopher Kings-Lynne

I think anything else will have to be done individually, although the
pattern can be copied.

Perhaps we should take bids on what should/should not be covered.


Everything should be covered, otherwise it's just annoying for users...

Chris


---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


Re: [PATCHES] drop if exists

2005-11-16 Thread Michael Glaesemann


On Nov 17, 2005, at 11:45 , Christopher Kings-Lynne wrote:


I think anything else will have to be done individually, although the
pattern can be copied.
Perhaps we should take bids on what should/should not be covered.


Everything should be covered, otherwise it's just annoying for  
users...


Including objects that already have CREATE OR REPLACE?

Michael Glaesemann
grzm myrealbox com




---(end of broadcast)---
TIP 4: Have you searched our list archives?

  http://archives.postgresql.org


[PATCHES] drop if exists

2005-11-14 Thread Andrew Dunstan


Ther attached patch is for comment. It implements drop if exists as 
has recently been discussed. Illustration:


andrew=# drop table blurflx;
ERROR:  table blurflx does not exist
andrew=# drop table if exists blurflx;
DROP TABLE
andrew=# create table blurflx ( x text);
CREATE TABLE
andrew=# drop table if exists blurflx;
DROP TABLE
andrew=# drop table blurflx;
ERROR:  table blurflx does not exist
andrew=#

If the patch is acceptable I will work up some documentation and 
regression tests.


cheers

andrew
Index: src/backend/commands/conversioncmds.c
===
RCS file: /cvsroot/pgsql/src/backend/commands/conversioncmds.c,v
retrieving revision 1.23
diff -c -r1.23 conversioncmds.c
*** src/backend/commands/conversioncmds.c	15 Oct 2005 02:49:15 -	1.23
--- src/backend/commands/conversioncmds.c	14 Nov 2005 14:09:52 -
***
*** 98,113 
   * DROP CONVERSION
   */
  void
! DropConversionCommand(List *name, DropBehavior behavior)
  {
  	Oid			conversionOid;
  
  	conversionOid = FindConversionByName(name);
  	if (!OidIsValid(conversionOid))
! 		ereport(ERROR,
! (errcode(ERRCODE_UNDEFINED_OBJECT),
!  errmsg(conversion \%s\ does not exist,
! 		NameListToString(name;
  
  	ConversionDrop(conversionOid, behavior);
  }
--- 98,118 
   * DROP CONVERSION
   */
  void
! DropConversionCommand(List *name, DropBehavior behavior, bool missing_ok)
  {
  	Oid			conversionOid;
  
  	conversionOid = FindConversionByName(name);
  	if (!OidIsValid(conversionOid))
! 	{
! 		if (missing_ok)
! 			return;
! 		else
! 			ereport(ERROR,
! 	(errcode(ERRCODE_UNDEFINED_OBJECT),
! 	 errmsg(conversion \%s\ does not exist,
! 			NameListToString(name;
! 	}
  
  	ConversionDrop(conversionOid, behavior);
  }
Index: src/backend/commands/schemacmds.c
===
RCS file: /cvsroot/pgsql/src/backend/commands/schemacmds.c,v
retrieving revision 1.35
diff -c -r1.35 schemacmds.c
*** src/backend/commands/schemacmds.c	15 Oct 2005 02:49:15 -	1.35
--- src/backend/commands/schemacmds.c	14 Nov 2005 14:09:52 -
***
*** 147,153 
   *		Removes a schema.
   */
  void
! RemoveSchema(List *names, DropBehavior behavior)
  {
  	char	   *namespaceName;
  	Oid			namespaceId;
--- 147,153 
   *		Removes a schema.
   */
  void
! RemoveSchema(List *names, DropBehavior behavior, bool missing_ok)
  {
  	char	   *namespaceName;
  	Oid			namespaceId;
***
*** 163,171 
   CStringGetDatum(namespaceName),
   0, 0, 0);
  	if (!OidIsValid(namespaceId))
! 		ereport(ERROR,
! (errcode(ERRCODE_UNDEFINED_SCHEMA),
!  errmsg(schema \%s\ does not exist, namespaceName)));
  
  	/* Permission check */
  	if (!pg_namespace_ownercheck(namespaceId, GetUserId()))
--- 163,176 
   CStringGetDatum(namespaceName),
   0, 0, 0);
  	if (!OidIsValid(namespaceId))
! 	{
! 		if (missing_ok)
! 			return;
! 		else
! 			ereport(ERROR,
! 	(errcode(ERRCODE_UNDEFINED_SCHEMA),
! 	 errmsg(schema \%s\ does not exist, namespaceName)));
! 	}
  
  	/* Permission check */
  	if (!pg_namespace_ownercheck(namespaceId, GetUserId()))
Index: src/backend/commands/typecmds.c
===
RCS file: /cvsroot/pgsql/src/backend/commands/typecmds.c,v
retrieving revision 1.82
diff -c -r1.82 typecmds.c
*** src/backend/commands/typecmds.c	18 Oct 2005 01:06:24 -	1.82
--- src/backend/commands/typecmds.c	14 Nov 2005 14:09:54 -
***
*** 398,404 
   *		Removes a datatype.
   */
  void
! RemoveType(List *names, DropBehavior behavior)
  {
  	TypeName   *typename;
  	Oid			typeoid;
--- 398,404 
   *		Removes a datatype.
   */
  void
! RemoveType(List *names, DropBehavior behavior, bool missing_ok)
  {
  	TypeName   *typename;
  	Oid			typeoid;
***
*** 414,423 
  	/* Use LookupTypeName here so that shell types can be removed. */
  	typeoid = LookupTypeName(typename);
  	if (!OidIsValid(typeoid))
! 		ereport(ERROR,
! (errcode(ERRCODE_UNDEFINED_OBJECT),
!  errmsg(type \%s\ does not exist,
! 		TypeNameToString(typename;
  
  	tup = SearchSysCache(TYPEOID,
  		 ObjectIdGetDatum(typeoid),
--- 414,428 
  	/* Use LookupTypeName here so that shell types can be removed. */
  	typeoid = LookupTypeName(typename);
  	if (!OidIsValid(typeoid))
! 	{
! 		if (missing_ok)
! 			return;
! 		else
! 			ereport(ERROR,
! 	(errcode(ERRCODE_UNDEFINED_OBJECT),
! 	 errmsg(type \%s\ does not exist,
! 			TypeNameToString(typename;
! 	}
  
  	tup = SearchSysCache(TYPEOID,
  		 ObjectIdGetDatum(typeoid),
***
*** 779,785 
   * This is identical to RemoveType except we insist it be a domain.
   */
  void
! RemoveDomain(List *names, DropBehavior behavior)
  {
  	TypeName   *typename;
  	Oid			typeoid;
--- 784,790 
   * This is identical to RemoveType except 

Re: [PATCHES] drop if exists

2005-11-14 Thread Michael Glaesemann


On Nov 14, 2005, at 23:25 , Andrew Dunstan wrote:



Ther attached patch is for comment. It implements drop if exists  
as has recently been discussed. Illustration:


Nifty! Thanks for working this up, Andrew!



andrew=# drop table blurflx;
ERROR:  table blurflx does not exist
andrew=# drop table if exists blurflx;
DROP TABLE


I'm not sure what other DBMS' return in this situation (and kindly  
ignore this suggestion if it's specified or otherwise determined),  
but perhaps the output could be TABLE blurlx DOES NOT EXIST  
(without the ERROR) or something more informative, rather than DROP  
TABLE. It reminds me of the old behavior of outputting COMMIT even in  
the case of transaction failure. I find the current behavior of  
outputting ROLLBACK in the case of transaction failure more useful.


Michael Glaesemann
grzm myrealbox com




---(end of broadcast)---
TIP 6: explain analyze is your friend


Re: [PATCHES] drop if exists

2005-11-14 Thread Dave Page
 

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of 
 Michael Glaesemann
 Sent: 14 November 2005 14:54
 To: Andrew Dunstan
 Cc: Patches (PostgreSQL)
 Subject: Re: [PATCHES] drop if exists
 
 
 On Nov 14, 2005, at 23:25 , Andrew Dunstan wrote:
 
 
  Ther attached patch is for comment. It implements drop if exists  
  as has recently been discussed. Illustration:
 
 Nifty! Thanks for working this up, Andrew!
 
 
  andrew=# drop table blurflx;
  ERROR:  table blurflx does not exist
  andrew=# drop table if exists blurflx;
  DROP TABLE
 
 I'm not sure what other DBMS' return in this situation (and kindly  
 ignore this suggestion if it's specified or otherwise determined),  
 but perhaps the output could be TABLE blurlx DOES NOT EXIST  
 (without the ERROR) or something more informative, rather than DROP  
 TABLE. It reminds me of the old behavior of outputting COMMIT 
 even in  
 the case of transaction failure. I find the current behavior of  
 outputting ROLLBACK in the case of transaction failure more useful.

Yes, a notice would certainly be nice:

andrew=# drop table blurflx;
ERROR:  table blurflx does not exist
andrew=# drop table if exists blurflx;
NOTICE: table blurflx does not exist
DROP TABLE

Regards, Dave.

---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq


Re: [PATCHES] drop if exists

2005-11-14 Thread Tom Lane
Andrew Dunstan [EMAIL PROTECTED] writes:
 andrew=# drop table blurflx;
 ERROR:  table blurflx does not exist
 andrew=# drop table if exists blurflx;
 DROP TABLE

If I read MySQL's documentation correctly, they emit a NOTE (equivalent
of a NOTICE message I suppose) when IF EXISTS does nothing because the
table doesn't exist.  Seems like we should do likewise --- your second
example here seems actively misleading.  That is, I'd rather see

andrew=# drop table if exists blurflx;
NOTICE:  table blurflx does not exist, skipping
DROP TABLE


regards, tom lane

---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
   subscribe-nomail command to [EMAIL PROTECTED] so that your
   message can get through to the mailing list cleanly


Re: [PATCHES] drop if exists

2005-11-14 Thread Andrew Dunstan


OK, now it looks like this:

andrew=# drop table blurflx;
ERROR:  table blurflx does not exist
andrew=# drop table if exists blurflx;
NOTICE:  table blurflx does not exist, skipping
DROP TABLE
andrew=# create table blurflx ( x text);
CREATE TABLE
andrew=# drop table if exists blurflx;
DROP TABLE
andrew=# drop table blurflx;
ERROR:  table blurflx does not exist
andrew=#

revised patch attached.

cheers

andrew

Tom Lane wrote:


Andrew Dunstan [EMAIL PROTECTED] writes:
 


andrew=# drop table blurflx;
ERROR:  table blurflx does not exist
andrew=# drop table if exists blurflx;
DROP TABLE
   



If I read MySQL's documentation correctly, they emit a NOTE (equivalent
of a NOTICE message I suppose) when IF EXISTS does nothing because the
table doesn't exist.  Seems like we should do likewise --- your second
example here seems actively misleading.  That is, I'd rather see

andrew=# drop table if exists blurflx;
NOTICE:  table blurflx does not exist, skipping
DROP TABLE


regards, tom lane

 

Index: src/backend/commands/conversioncmds.c
===
RCS file: /cvsroot/pgsql/src/backend/commands/conversioncmds.c,v
retrieving revision 1.23
diff -c -r1.23 conversioncmds.c
*** src/backend/commands/conversioncmds.c	15 Oct 2005 02:49:15 -	1.23
--- src/backend/commands/conversioncmds.c	14 Nov 2005 17:00:05 -
***
*** 98,113 
   * DROP CONVERSION
   */
  void
! DropConversionCommand(List *name, DropBehavior behavior)
  {
  	Oid			conversionOid;
  
  	conversionOid = FindConversionByName(name);
  	if (!OidIsValid(conversionOid))
! 		ereport(ERROR,
! (errcode(ERRCODE_UNDEFINED_OBJECT),
!  errmsg(conversion \%s\ does not exist,
! 		NameListToString(name;
  
  	ConversionDrop(conversionOid, behavior);
  }
--- 98,128 
   * DROP CONVERSION
   */
  void
! DropConversionCommand(List *name, DropBehavior behavior, bool missing_ok)
  {
  	Oid			conversionOid;
  
  	conversionOid = FindConversionByName(name);
  	if (!OidIsValid(conversionOid))
! 	{
! 		if (! missing_ok)
! 		{
! 			ereport(ERROR,
! 	(errcode(ERRCODE_UNDEFINED_OBJECT),
! 	 errmsg(conversion \%s\ does not exist,
! 			NameListToString(name;
! 		}
! 		else
! 		{
! 			ereport(NOTICE,
! 	(errcode(ERRCODE_UNDEFINED_OBJECT),
! 	 errmsg(conversion \%s\ does not exist, skipping,
! 			NameListToString(name;
! 		}
! 
! 		Assert(missing_ok);
! 		return;
! 	}
  
  	ConversionDrop(conversionOid, behavior);
  }
Index: src/backend/commands/schemacmds.c
===
RCS file: /cvsroot/pgsql/src/backend/commands/schemacmds.c,v
retrieving revision 1.35
diff -c -r1.35 schemacmds.c
*** src/backend/commands/schemacmds.c	15 Oct 2005 02:49:15 -	1.35
--- src/backend/commands/schemacmds.c	14 Nov 2005 17:00:05 -
***
*** 147,153 
   *		Removes a schema.
   */
  void
! RemoveSchema(List *names, DropBehavior behavior)
  {
  	char	   *namespaceName;
  	Oid			namespaceId;
--- 147,153 
   *		Removes a schema.
   */
  void
! RemoveSchema(List *names, DropBehavior behavior, bool missing_ok)
  {
  	char	   *namespaceName;
  	Oid			namespaceId;
***
*** 163,171 
   CStringGetDatum(namespaceName),
   0, 0, 0);
  	if (!OidIsValid(namespaceId))
! 		ereport(ERROR,
! (errcode(ERRCODE_UNDEFINED_SCHEMA),
!  errmsg(schema \%s\ does not exist, namespaceName)));
  
  	/* Permission check */
  	if (!pg_namespace_ownercheck(namespaceId, GetUserId()))
--- 163,186 
   CStringGetDatum(namespaceName),
   0, 0, 0);
  	if (!OidIsValid(namespaceId))
! 	{
! 		if (!missing_ok)
! 		{
! 			ereport(ERROR,
! 	(errcode(ERRCODE_UNDEFINED_SCHEMA),
! 	 errmsg(schema \%s\ does not exist, namespaceName)));
! 		}
! 		else
! 		{
! 			ereport(NOTICE,
! 	(errcode(ERRCODE_UNDEFINED_SCHEMA),
! 	 errmsg(schema \%s\ does not exist, skipping, 
! 			namespaceName)));
! 		}
! 
! 		Assert(missing_ok);
! 		return;
! 	}
  
  	/* Permission check */
  	if (!pg_namespace_ownercheck(namespaceId, GetUserId()))
Index: src/backend/commands/typecmds.c
===
RCS file: /cvsroot/pgsql/src/backend/commands/typecmds.c,v
retrieving revision 1.82
diff -c -r1.82 typecmds.c
*** src/backend/commands/typecmds.c	18 Oct 2005 01:06:24 -	1.82
--- src/backend/commands/typecmds.c	14 Nov 2005 17:00:05 -
***
*** 398,404 
   *		Removes a datatype.
   */
  void
! RemoveType(List *names, DropBehavior behavior)
  {
  	TypeName   *typename;
  	Oid			typeoid;
--- 398,404 
   *		Removes a datatype.
   */
  void
! RemoveType(List *names, DropBehavior behavior, bool missing_ok)
  {
  	TypeName   *typename;
  	Oid			typeoid;
***
*** 414,423 
  	/* Use LookupTypeName here so that shell types can be removed. */
  	typeoid = LookupTypeName(typename);
  	if