I've written a small patch that could be useful for people with old
applications, since it restores the original behaviour of silently treating
empty strings as 0 (at least for integers). It introduces a new bool GUC
variable "empty_equals_0" with default "off". With a simple "SET
empty_equals_0 to on" or via "ALTER DATABASE FOO ... SET empty_equals_0 to
on" the pre 7.3 behaviour can be restored again on a per database base.
I don't think such a patch is worthy for inclusion in postgresql, but as
external patch it's useful. What's the best place to submit such a patch?
gborg?
Thanks for the info!
diff -Nurb ../postgresql-7.4.2.orig/src/backend/utils/adt/numutils.c ./src/backend/utils/adt/numutils.c
--- ../postgresql-7.4.2.orig/src/backend/utils/adt/numutils.c 2003-09-25 08:58:04.000000000 +0200
+++ ./src/backend/utils/adt/numutils.c 2004-04-30 11:37:35.977932032 +0200
@@ -43,6 +43,9 @@
#endif
+bool empty_equals_0;
+
+
/*
* pg_atoi: convert string to integer
*
@@ -67,6 +70,9 @@
if (s == (char *) NULL)
elog(ERROR, "NULL pointer");
if (*s == 0)
+ if(empty_equals_0)
+ return (int32)0;
+ else
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for integer: \"%s\"",
diff -Nurb ../postgresql-7.4.2.orig/src/backend/utils/misc/guc.c ./src/backend/utils/misc/guc.c
--- ../postgresql-7.4.2.orig/src/backend/utils/misc/guc.c 2004-02-23 21:46:16.000000000 +0100
+++ ./src/backend/utils/misc/guc.c 2004-04-30 11:28:31.302735248 +0200
@@ -73,6 +73,7 @@
extern int CommitDelay;
extern int CommitSiblings;
extern char *preload_libraries_string;
+extern int empty_equals_0;
#ifdef HAVE_SYSLOG
extern char *Syslog_facility;
@@ -748,6 +749,14 @@
true, NULL, NULL
},
{
+ {"empty_equals_0", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
+ gettext_noop("Treats the empty string as 0 when dealing with integers"),
+ NULL
+ },
+ &empty_equals_0,
+ false, NULL, NULL
+ },
+ {
{"australian_timezones", PGC_USERSET, CLIENT_CONN_LOCALE,
gettext_noop("Interprets ACST, CST, EST, and SAT as Australian time zones."),
gettext_noop("Otherwise they are interpreted as North/South American "
diff -Nurb ../postgresql-7.4.2.orig/src/bin/psql/tab-complete.c ./src/bin/psql/tab-complete.c
--- ../postgresql-7.4.2.orig/src/bin/psql/tab-complete.c 2003-11-08 21:54:37.000000000 +0100
+++ ./src/bin/psql/tab-complete.c 2004-04-30 11:36:41.703183048 +0200
@@ -501,6 +501,7 @@
"default_transaction_read_only",
"dynamic_library_path",
"effective_cache_size",
+ "empty_equals_0",
"enable_hashagg",
"enable_hashjoin",
"enable_indexscan",
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]