diff --git a/lib/modules/Sql.pmod/pgsql.pike b/lib/modules/Sql.pmod/pgsql.pike
index b1b62567dc8d555c9712a581d48164962142be34..4eba9ef7240fc8ddd5256e9a47439e57f157769b 100644
--- a/lib/modules/Sql.pmod/pgsql.pike
+++ b/lib/modules/Sql.pmod/pgsql.pike
@@ -86,6 +86,8 @@ private Thread.Mutex resyncmux;
 
 protected string _sprintf(int type) {
   string res;
+  if (!this)					// Not in destructed objects
+    return "";
   switch(type) {
     case 'O':
       res = sprintf(DRIVERNAME"(%s@%s:%d/%s,%d,%d)",
diff --git a/lib/modules/Sql.pmod/pgsql_util.pmod b/lib/modules/Sql.pmod/pgsql_util.pmod
index 99fd4622fe499c04533cdb7f4d3addd92622b879..4c767f7a2207d33af7fb456d10331da6fc3efbbc 100644
--- a/lib/modules/Sql.pmod/pgsql_util.pmod
+++ b/lib/modules/Sql.pmod/pgsql_util.pmod
@@ -717,6 +717,8 @@ outer:
 
   private string _sprintf(int type) {
     string res;
+    if (!this)					// Not in destructed objects
+      return "";
     switch (type) {
       case 'O':
         int fd = -1;
@@ -822,6 +824,8 @@ class sql_result {
 
   protected string _sprintf(int type) {
     string res;
+    if (!this)					// Not in destructed objects
+      return "";
     switch (type) {
       case 'O':
         int fd = -1;
@@ -1822,6 +1826,8 @@ class proxy {
 
   private string _sprintf(int type) {
     string res;
+    if (!this)					// Not in destructed objects
+      return "";
     switch (type) {
       case 'O':
         res = sprintf(DRIVERNAME".proxy(%s@%s:%d/%s,%d,%d)",