Re: [PATCHES] create or replace language

2008-05-15 Thread Andreas 'ads' Scherbaum
On Thu, 15 May 2008 12:29:11 +0100 Heikki Linnakangas wrote:

> Andreas 'ads' Scherbaum wrote:
> > Attached is another version of the patch (still missing documentation),
> > which changes the language owner on update (the owner can still be
> > changed in pg_pltemplate).
> 
> The other CREATE OR REPLACE commands don't change the owner, so CREATE 
> OR REPLACE LANGUAGE shouldn't do that either.

It's possible that the language owner is changed in the meantime (in
pg_pltemplate). Since the owner cannot be changed from the "CREATE OR
REPLACE" syntax, a modified owner in the template table is the only
possibility where a new owner can came from. If "CREATE LANGUAGE"
find's a language entry in pg_pltemplate, it drops any data from the
commandline and uses the data from the template - so a new owner is
something which should be distributed along with the REPLACE.


> >> So do we want to replace any data (in my opinion only the validator is
> >> left) at all or just skip any error message?
> 
> I think you should be able to change handler and validator functions, 
> and the trusted flag. Or is there a reason to not allow that?

Message-ID: <[EMAIL PROTECTED]>
No other answer yet.


Kind regards

-- 
Andreas 'ads' Scherbaum
German PostgreSQL User Group

-- 
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches


Re: [PATCHES] create or replace language

2008-05-15 Thread Heikki Linnakangas

Andreas 'ads' Scherbaum wrote:

Attached is another version of the patch (still missing documentation),
which changes the language owner on update (the owner can still be
changed in pg_pltemplate).


The other CREATE OR REPLACE commands don't change the owner, so CREATE 
OR REPLACE LANGUAGE shouldn't do that either.



So do we want to replace any data (in my opinion only the validator is
left) at all or just skip any error message?


I think you should be able to change handler and validator functions, 
and the trusted flag. Or is there a reason to not allow that?


--
  Heikki Linnakangas
  EnterpriseDB   http://www.enterprisedb.com

--
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches


Re: [PATCHES] create or replace language

2008-05-15 Thread Andreas 'ads' Scherbaum
On Sat, 10 May 2008 09:36:26 +0200 Andreas 'ads' Scherbaum wrote:

> On Sat, 3 May 2008 21:12:51 +0200 Andreas 'ads' Scherbaum wrote:
> > On Sat, 03 May 2008 13:34:05 -0400 Tom Lane wrote:
> > 
> > > So maybe the right thing is that CREATE OR REPLACE LANGUAGE can change
> > > "inessential" properties of an existing language, but not the core
> > > properties --- which might only be the handler function, though you
> > > could make a case for the validator and the trusted flag as well.
> > 
> > Already thought about that: exchanging the handler function or the
> > libbrary might only be useful in a developing environment, i don't see
> > other use cases here. The same is true for the validator (but a missing
> > validator could be added afterwards) and in my opinion i would prefer
> > not to change the trust flag - some functions may depend on this.
> > 
> > The name cannot be changed at all so only the owner and maybe the
> > validator is left ...
> 
> Even the owner does not make sense, because it seems it is not possible
> that the owner will changed through the SQL interface. ALTER LANGUAGE
> already exists for this purpose and CREATE LANGUAGE has no option for
> the language owner.

Attached is another version of the patch (still missing documentation),
which changes the language owner on update (the owner can still be
changed in pg_pltemplate).


> So do we want to replace any data (in my opinion only the validator is
> left) at all or just skip any error message?

Anyone has an opinion here?


Kind regards

-- 
Andreas 'ads' Scherbaum
German PostgreSQL User Group
diff -x CVS -ruN pgsql.orig/src/backend/commands/proclang.c pgsql/src/backend/commands/proclang.c
--- pgsql.orig/src/backend/commands/proclang.c	2008-04-29 23:59:02.0 +0200
+++ pgsql/src/backend/commands/proclang.c	2008-05-15 12:18:39.0 +0200
@@ -48,7 +48,7 @@
 } PLTemplate;
 
 static void create_proc_lang(const char *languageName,
- Oid languageOwner, Oid handlerOid, Oid valOid, bool trusted);
+ Oid languageOwner, Oid handlerOid, Oid valOid, bool trusted, int replace);
 static PLTemplate *find_language_template(const char *languageName);
 static void AlterLanguageOwner_internal(HeapTuple tup, Relation rel,
 			Oid newOwnerId);
@@ -67,6 +67,7 @@
 valOid;
 	Oid			funcrettype;
 	Oid			funcargtypes[1];
+	int			replace; /* store info about replace */
 
 	/*
 	 * Translate the language name and check that this language doesn't
@@ -74,12 +75,26 @@
 	 */
 	languageName = case_translate_language_name(stmt->plname);
 
+
+	replace = 0;
 	if (SearchSysCacheExists(LANGNAME,
 			 PointerGetDatum(languageName),
 			 0, 0, 0))
-		ereport(ERROR,
-(errcode(ERRCODE_DUPLICATE_OBJECT),
- errmsg("language \"%s\" already exists", languageName)));
+	{
+		if (stmt->replace)
+		{
+			/* if the language exist but "OR REPLACE" is given, we just remember
+			 * the fact here */
+			replace = 1;
+		}
+		else
+		{
+			ereport(ERROR,
+	(errcode(ERRCODE_DUPLICATE_OBJECT),
+	 errmsg("language \"%s\" already exists", languageName)));
+		}
+	}
+
 
 	/*
 	 * If we have template information for the language, ignore the supplied
@@ -131,7 +146,7 @@
 		{
 			handlerOid = ProcedureCreate(pltemplate->tmplhandler,
 		 PG_CATALOG_NAMESPACE,
-		 false, /* replace */
+		 stmt->replace, /* replace */
 		 false, /* returnsSet */
 		 LANGUAGE_HANDLEROID,
 		 ClanguageId,
@@ -164,7 +179,7 @@
 			{
 valOid = ProcedureCreate(pltemplate->tmplvalidator,
 		 PG_CATALOG_NAMESPACE,
-		 false, /* replace */
+		 stmt->replace, /* replace */
 		 false, /* returnsSet */
 		 VOIDOID,
 		 ClanguageId,
@@ -189,7 +204,7 @@
 
 		/* ok, create it */
 		create_proc_lang(languageName, GetUserId(), handlerOid, valOid,
-		 pltemplate->tmpltrusted);
+		 pltemplate->tmpltrusted, replace);
 	}
 	else
 	{
@@ -253,7 +268,7 @@
 
 		/* ok, create it */
 		create_proc_lang(languageName, GetUserId(), handlerOid, valOid,
-		 stmt->pltrusted);
+		 stmt->pltrusted, replace);
 	}
 }
 
@@ -262,7 +277,7 @@
  */
 static void
 create_proc_lang(const char *languageName,
- Oid languageOwner, Oid handlerOid, Oid valOid, bool trusted)
+ Oid languageOwner, Oid handlerOid, Oid valOid, bool trusted, int replace)
 {
 	Relation	rel;
 	TupleDesc	tupDesc;
@@ -273,56 +288,83 @@
 	ObjectAddress myself,
 referenced;
 
-	/*
-	 * Insert the new language into pg_language
-	 */
-	rel = heap_open(LanguageRelationId, RowExclusiveLock);
-	tupDesc = rel->rd_att;
+	if (replace == 0)
+	{
+		/*
+		 * Insert the new language into pg_language
+		 */
+		rel = heap_open(LanguageRelationId, RowExclusiveLock);
+		tupDesc = rel->rd_att;
 
-	memset(values, 0, sizeof(values));
-	memset(nulls, ' ', sizeof(nulls));
+		memset(values, 0, sizeof(values));
+		memset(nulls, ' ', sizeof(nulls));
 
-	namestrcpy(&langname, languageName);
-	values[Anum_pg_lan

Re: [PATCHES] create or replace language

2008-05-10 Thread Andreas 'ads' Scherbaum
On Sat, 3 May 2008 21:12:51 +0200 Andreas 'ads' Scherbaum wrote:
> On Sat, 03 May 2008 13:34:05 -0400 Tom Lane wrote:
> 
> > So maybe the right thing is that CREATE OR REPLACE LANGUAGE can change
> > "inessential" properties of an existing language, but not the core
> > properties --- which might only be the handler function, though you
> > could make a case for the validator and the trusted flag as well.
> 
> Already thought about that: exchanging the handler function or the
> libbrary might only be useful in a developing environment, i don't see
> other use cases here. The same is true for the validator (but a missing
> validator could be added afterwards) and in my opinion i would prefer
> not to change the trust flag - some functions may depend on this.
> 
> The name cannot be changed at all so only the owner and maybe the
> validator is left ...

Even the owner does not make sense, because it seems it is not possible
that the owner will changed through the SQL interface. ALTER LANGUAGE
already exists for this purpose and CREATE LANGUAGE has no option for
the language owner.

So do we want to replace any data (in my opinion only the validator is
left) at all or just skip any error message?


Kind regards

-- 
Andreas 'ads' Scherbaum
German PostgreSQL User Group

-- 
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches


Re: [PATCHES] create or replace language

2008-05-05 Thread Tom Lane
Gregory Stark <[EMAIL PROTECTED]> writes:
> "Tom Lane" <[EMAIL PROTECTED]> writes:
>> ...  So maybe the right thing is that
>> CREATE OR REPLACE LANGUAGE can change "inessential" properties of an
>> existing language, but not the core properties --- which might only be
>> the handler function, though you could make a case for the validator and
>> the trusted flag as well.

> I'm not so sure. What about if a PL language wants to include a version number
> in the language handler? Or if a new version has to change the name for some
> reason -- perhaps they discover that the old name doesn't work on some linkers
> for some reason.

Not sure that I find those cases convincing.  Remember that what CREATE
OR REPLACE LANGUAGE is going to be referring to is the handler
function's SQL-level name; there's already a layer of indirection
between it and link-level issues.

regards, tom lane

-- 
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches


Re: [PATCHES] create or replace language

2008-05-05 Thread Gregory Stark
"Tom Lane" <[EMAIL PROTECTED]> writes:

> The equivalent problem for views and functions is handled by restricting
> CREATE OR REPLACE to not change the output column set of a view or the
> type signature of a function, independently of whether there are any
> actual references to the object.  So maybe the right thing is that
> CREATE OR REPLACE LANGUAGE can change "inessential" properties of an
> existing language, but not the core properties --- which might only be
> the handler function, though you could make a case for the validator and
> the trusted flag as well.

I'm not so sure. What about if a PL language wants to include a version number
in the language handler? Or if a new version has to change the name for some
reason -- perhaps they discover that the old name doesn't work on some linkers
for some reason.

-- 
  Gregory Stark
  EnterpriseDB  http://www.enterprisedb.com
  Get trained by Bruce Momjian - ask me about EnterpriseDB's PostgreSQL 
training!

-- 
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches


Re: [PATCHES] create or replace language

2008-05-03 Thread Andreas 'ads' Scherbaum

Hello,

On Sat, 03 May 2008 13:34:05 -0400 Tom Lane wrote:

> So maybe the right thing is that CREATE OR REPLACE LANGUAGE can change
> "inessential" properties of an existing language, but not the core
> properties --- which might only be the handler function, though you
> could make a case for the validator and the trusted flag as well.

Already thought about that: exchanging the handler function or the
libbrary might only be useful in a developing environment, i don't see
other use cases here. The same is true for the validator (but a missing
validator could be added afterwards) and in my opinion i would prefer
not to change the trust flag - some functions may depend on this.

The name cannot be changed at all so only the owner and maybe the
validator is left ...

Did i miss something?


Kind regards

-- 
Andreas 'ads' Scherbaum
German PostgreSQL User Group

-- 
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches


Re: [PATCHES] create or replace language

2008-05-03 Thread Tom Lane
"Andreas 'ads' Scherbaum" <[EMAIL PROTECTED]> writes:
> Attached is a first version for the "CREATE OR REPLACE LANGUAGE" patch.
> It's still missing some functionality (especially the update part is
> far away from being complete) and it's also missing documentation.

It strikes me that if there are any existing functions in the language,
we might want to restrict what can be changed by CREATE OR REPLACE.
For instance switching to a completely different language handler
doesn't seem like a great idea.

The equivalent problem for views and functions is handled by restricting
CREATE OR REPLACE to not change the output column set of a view or the
type signature of a function, independently of whether there are any
actual references to the object.  So maybe the right thing is that
CREATE OR REPLACE LANGUAGE can change "inessential" properties of an
existing language, but not the core properties --- which might only be
the handler function, though you could make a case for the validator and
the trusted flag as well.

regards, tom lane

-- 
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches


Re: [PATCHES] create or replace language

2008-05-03 Thread Andreas 'ads' Scherbaum
On Sat, 29 Mar 2008 22:35:21 -0400 Tom Lane wrote:

> The key argument seems to be that it's quite unclear what the state
> following CREATE IF NOT EXISTS (CINE) should be, if the object does
> exist but not with the same properties specified in the CINE command.
> CREATE OR REPLACE resolves that by making it clear that it's gonna be
> what the command says.  Perhaps there is a use-case for the alternate
> behavior where the pre-existing object doesn't get modified, but I'm
> not too sure what it would be.

Attached is a first version for the "CREATE OR REPLACE LANGUAGE" patch.
It's still missing some functionality (especially the update part is
far away from being complete) and it's also missing documentation.

I just want to know if i'm heading in the right direction or if
something is totally broken in my basic approach:


In case a language is already in pg_pltemplate, the (possibly changed)
values from this table are used to update the pg_languages entry. This
gives the ability to change the owner, trust status, the language or
validator handler.

In case the language is not in pg_pltemplate, the values from the
commandline are used, just like "create language".



Thanks & kind regards

-- 
Andreas 'ads' Scherbaum
German PostgreSQL User Group
diff -x CVS -ruN pgsql.orig/src/backend/commands/proclang.c pgsql/src/backend/commands/proclang.c
--- pgsql.orig/src/backend/commands/proclang.c	2008-04-29 23:59:02.0 +0200
+++ pgsql/src/backend/commands/proclang.c	2008-05-03 18:28:50.0 +0200
@@ -48,7 +48,7 @@
 } PLTemplate;
 
 static void create_proc_lang(const char *languageName,
- Oid languageOwner, Oid handlerOid, Oid valOid, bool trusted);
+ Oid languageOwner, Oid handlerOid, Oid valOid, bool trusted, int replace);
 static PLTemplate *find_language_template(const char *languageName);
 static void AlterLanguageOwner_internal(HeapTuple tup, Relation rel,
 			Oid newOwnerId);
@@ -67,6 +67,7 @@
 valOid;
 	Oid			funcrettype;
 	Oid			funcargtypes[1];
+	int			replace; /* store info about replace */
 
 	/*
 	 * Translate the language name and check that this language doesn't
@@ -74,12 +75,24 @@
 	 */
 	languageName = case_translate_language_name(stmt->plname);
 
+
+	replace = 0;
 	if (SearchSysCacheExists(LANGNAME,
 			 PointerGetDatum(languageName),
 			 0, 0, 0))
-		ereport(ERROR,
-(errcode(ERRCODE_DUPLICATE_OBJECT),
- errmsg("language \"%s\" already exists", languageName)));
+	{
+		if (stmt->replace)
+		{
+			replace = 1;
+		}
+		else
+		{
+			ereport(ERROR,
+	(errcode(ERRCODE_DUPLICATE_OBJECT),
+	 errmsg("language \"%s\" already exists", languageName)));
+		}
+	}
+
 
 	/*
 	 * If we have template information for the language, ignore the supplied
@@ -131,7 +144,7 @@
 		{
 			handlerOid = ProcedureCreate(pltemplate->tmplhandler,
 		 PG_CATALOG_NAMESPACE,
-		 false, /* replace */
+		 stmt->replace, /* replace */
 		 false, /* returnsSet */
 		 LANGUAGE_HANDLEROID,
 		 ClanguageId,
@@ -164,7 +177,7 @@
 			{
 valOid = ProcedureCreate(pltemplate->tmplvalidator,
 		 PG_CATALOG_NAMESPACE,
-		 false, /* replace */
+		 stmt->replace, /* replace */
 		 false, /* returnsSet */
 		 VOIDOID,
 		 ClanguageId,
@@ -189,7 +202,7 @@
 
 		/* ok, create it */
 		create_proc_lang(languageName, GetUserId(), handlerOid, valOid,
-		 pltemplate->tmpltrusted);
+		 pltemplate->tmpltrusted, replace);
 	}
 	else
 	{
@@ -253,7 +266,7 @@
 
 		/* ok, create it */
 		create_proc_lang(languageName, GetUserId(), handlerOid, valOid,
-		 stmt->pltrusted);
+		 stmt->pltrusted, replace);
 	}
 }
 
@@ -262,67 +275,125 @@
  */
 static void
 create_proc_lang(const char *languageName,
- Oid languageOwner, Oid handlerOid, Oid valOid, bool trusted)
+ Oid languageOwner, Oid handlerOid, Oid valOid, bool trusted, int replace)
 {
 	Relation	rel;
 	TupleDesc	tupDesc;
 	Datum		values[Natts_pg_language];
 	char		nulls[Natts_pg_language];
+	char		replaces[Natts_pg_language];
 	NameData	langname;
 	HeapTuple	tup;
 	ObjectAddress myself,
 referenced;
 
-	/*
-	 * Insert the new language into pg_language
-	 */
-	rel = heap_open(LanguageRelationId, RowExclusiveLock);
-	tupDesc = rel->rd_att;
+	if (replace == 0)
+	{
+		/*
+		 * Insert the new language into pg_language
+		 */
+		rel = heap_open(LanguageRelationId, RowExclusiveLock);
+		tupDesc = rel->rd_att;
 
-	memset(values, 0, sizeof(values));
-	memset(nulls, ' ', sizeof(nulls));
+		memset(values, 0, sizeof(values));
+		memset(nulls, ' ', sizeof(nulls));
 
-	namestrcpy(&langname, languageName);
-	values[Anum_pg_language_lanname - 1] = NameGetDatum(&langname);
-	values[Anum_pg_language_lanowner - 1] = ObjectIdGetDatum(languageOwner);
-	values[Anum_pg_language_lanispl - 1] = BoolGetDatum(true);
-	values[Anum_pg_language_lanpltrusted - 1] = BoolGetDatum(trusted);
-	values[Anum_pg_language_lanplcallfoid - 1] =