Patch: create or replace language

Started by Andreas 'ads' Scherbaumover 16 years ago8 messages
#1Andreas 'ads' Scherbaum
adsmail@wars-nicht.de
1 attachment(s)

Hello,

following this old discussion:

http://archives.postgresql.org/pgsql-patches/2008-03/msg00402.php

i modifies the patch to use the "CREATE [OR REPLACE] LANGUAGE" syntax.
If the patch is ok, i will add the documentation too.

Kind regards

--
Andreas 'ads' Scherbaum
German PostgreSQL User Group
European PostgreSQL User Group - Board of Directors
Volunteer Regional Contact, Germany - PostgreSQL Project

PGDay.eu 2009 in Paris, Nov. 6/7, http://www.pgday.eu/

Attachments:

create_or_replace_language_2009-10-06.patchtext/x-patch; name=create_or_replace_language_2009-10-06.patchDownload
Index: src/backend/commands/proclang.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/commands/proclang.c,v
retrieving revision 1.87
diff -r1.87 proclang.c
84,86c84,94
< 		ereport(ERROR,
< 				(errcode(ERRCODE_DUPLICATE_OBJECT),
< 				 errmsg("language \"%s\" already exists", languageName)));
---
> 		if (!stmt->replace)
> 			ereport(ERROR,
> 					(errcode(ERRCODE_DUPLICATE_OBJECT),
> 					 errmsg("language \"%s\" already exists", languageName)));
> 		else
> 		{
> 			ereport(NOTICE,
> 					(errmsg("language \"%s\" already exists, skipping", languageName)));
> 			return;
> 		}
> 
Index: src/backend/parser/gram.y
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/parser/gram.y,v
retrieving revision 2.679
diff -r2.679 gram.y
2768c2768
< 			CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
---
> 			CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2771c2771,2772
< 				n->plname = $5;
---
> 				n->replace = $2;
> 				n->plname = $6;
2779c2780
< 			| CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
---
> 			| CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2783,2787c2784,2789
< 				n->plname = $5;
< 				n->plhandler = $7;
< 				n->plinline = $8;
< 				n->plvalidator = $9;
< 				n->pltrusted = $2;
---
> 				n->replace = $2;
> 				n->plname = $6;
> 				n->plhandler = $8;
> 				n->plinline = $9;
> 				n->plvalidator = $10;
> 				n->pltrusted = $3;
Index: src/include/nodes/parsenodes.h
===================================================================
RCS file: /projects/cvsroot/pgsql/src/include/nodes/parsenodes.h,v
retrieving revision 1.402
diff -r1.402 parsenodes.h
1570a1571
> 	bool		replace;		/* T => replace if already exists */
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andreas 'ads' Scherbaum (#1)
Re: Patch: create or replace language

"Andreas 'ads' Scherbaum" <adsmail@wars-nicht.de> writes:

following this old discussion:
http://archives.postgresql.org/pgsql-patches/2008-03/msg00402.php
i modifies the patch to use the "CREATE [OR REPLACE] LANGUAGE" syntax.

This is not an "OR REPLACE" operation, because it doesn't replace
the existing definition. What you've got here is a CREATE IF NOT EXISTS
implementation that arbitrarily uses the other syntax. The point of
the previous discussion was summed up here:
http://archives.postgresql.org/pgsql-patches/2008-03/msg00416.php
namely that CREATE OR REPLACE should leave the object having the
properties specified in the command.

regards, tom lane

#3Alvaro Herrera
alvherre@commandprompt.com
In reply to: Andreas 'ads' Scherbaum (#1)
Re: Patch: create or replace language

Andreas 'ads' Scherbaum wrote:

Hello,

following this old discussion:

http://archives.postgresql.org/pgsql-patches/2008-03/msg00402.php

i modifies the patch to use the "CREATE [OR REPLACE] LANGUAGE" syntax.
If the patch is ok, i will add the documentation too.

Please send a context diff (however much ED IS THE STANDARD!!! TEXT
EDITOR, we don't like its patches here). Note that you probably missed
updates to other functions touching the node to which you add the
boolean. Also, per Tom's followup,

Index: src/include/nodes/parsenodes.h
===================================================================
RCS file: /projects/cvsroot/pgsql/src/include/nodes/parsenodes.h,v
retrieving revision 1.402
diff -r1.402 parsenodes.h
1570a1571

bool replace; /* T => replace if already exists */

this comment needs fixed.

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

#4Robert Haas
robertmhaas@gmail.com
In reply to: Alvaro Herrera (#3)
Re: Patch: create or replace language

On Tue, Oct 6, 2009 at 10:24 AM, Alvaro Herrera
<alvherre@commandprompt.com> wrote:

Andreas 'ads' Scherbaum wrote:

Hello,

following this old discussion:

http://archives.postgresql.org/pgsql-patches/2008-03/msg00402.php

i modifies the patch to use the "CREATE [OR REPLACE] LANGUAGE" syntax.
If the patch is ok, i will add the documentation too.

Please send a context diff (however much ED IS THE STANDARD!!! TEXT
EDITOR, we don't like its patches here).  Note that you probably missed
updates to other functions touching the node to which you add the
boolean.  Also, per Tom's followup,

Index: src/include/nodes/parsenodes.h
===================================================================
RCS file: /projects/cvsroot/pgsql/src/include/nodes/parsenodes.h,v
retrieving revision 1.402
diff -r1.402 parsenodes.h
1570a1571

    bool            replace;                /* T => replace if already exists */

this comment needs fixed.

Maybe I'm out of line to say this, but it seems to me that we should
not even be looking at newly-submitted patches at this point.

...Robert

#5Alvaro Herrera
alvherre@commandprompt.com
In reply to: Robert Haas (#4)
Re: Patch: create or replace language

Robert Haas escribi�:

On Tue, Oct 6, 2009 at 10:24 AM, Alvaro Herrera
<alvherre@commandprompt.com> wrote:

this comment needs fixed.

Maybe I'm out of line to say this, but it seems to me that we should
not even be looking at newly-submitted patches at this point.

Yeah, it was so short I didn't see any point in not commenting.

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: Robert Haas (#4)
Re: Patch: create or replace language

Robert Haas <robertmhaas@gmail.com> writes:

Maybe I'm out of line to say this, but it seems to me that we should
not even be looking at newly-submitted patches at this point.

It would have been more work to put it in the queue to reject later
than to reject it now ;-). Besides, this way Andreas has a chance
to rewrite it into something acceptable before the next CF.

regards, tom lane

#7Robert Haas
robertmhaas@gmail.com
In reply to: Tom Lane (#6)
Re: Patch: create or replace language

On Tue, Oct 6, 2009 at 10:48 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Robert Haas <robertmhaas@gmail.com> writes:

Maybe I'm out of line to say this, but it seems to me that we should
not even be looking at newly-submitted patches at this point.

It would have been more work to put it in the queue to reject later
than to reject it now ;-).  Besides, this way Andreas has a chance
to rewrite it into something acceptable before the next CF.

Fair enough.

...Robert

#8Bernd Helmle
mailings@oopsware.de
In reply to: Tom Lane (#2)
Re: Patch: create or replace language

--On 6. Oktober 2009 10:13:54 -0400 Tom Lane <tgl@sss.pgh.pa.us> wrote:

http://archives.postgresql.org/pgsql-patches/2008-03/msg00416.php
namely that CREATE OR REPLACE should leave the object having the
properties specified in the command.

Maybe when implementing this, it can be worth to keep an eye on ALTER
LANGUAGE too ?

--
Thanks

Bernd