Index: trunk/ippToPsps/jython/stackbatch.py
===================================================================
--- trunk/ippToPsps/jython/stackbatch.py	(revision 39097)
+++ trunk/ippToPsps/jython/stackbatch.py	(revision 39099)
@@ -64,4 +64,5 @@
        self.headerSet = {}
        self.md5sum = {}
+       self.stackEpochs = {}
 
        # we have two sets of imageIDs here:
@@ -113,4 +114,6 @@
            self.logger.infoPair(filter + " imageID = ", imageID)       
            self.imageIDs[filter] = imageID
+
+           self.stackEpochs[filter] = self.getKeyFloat(header, "%.10f", 'MJD-OBS')
 
 	   ## MEH -- md5sum test
@@ -374,4 +377,6 @@
             self.logger.infoPair("selecting imageID", imageID)
 
+            stackEpoch = self.stackEpochs[filter]
+
             # at this point, the StackObjectThin table includes objID and ippObjID
 
@@ -390,4 +395,6 @@
             sqlLine.group("a."+filter+"ra",            "b.ra")
             sqlLine.group("a."+filter+"dec",           "b.dec_")
+
+            sqlLine.group("a."+filter+"Epoch",         str(stackEpoch))
 
             sqlLine.group("a."+filter+"PSFMag",        "b.Mpsf")
@@ -1351,4 +1358,5 @@
         sql = "insert into StackObjectThin (objID, ippDetectID, ippObjID) select distinct objID, ippDetectID, ippObjID from dvoDetectionFull " + whereClause;
 
+        self.logger.debugPair("sql 1", sql)
         self.scratchDb.execute(sql)
 
@@ -1361,4 +1369,5 @@
               , processingVersion = '" + str(self.skychunk.processingVersion)  +"'"
               
+        self.logger.debugPair("sql 2", sql)
         self.scratchDb.execute(sql)
 
@@ -1366,6 +1375,12 @@
 
         for filter in self.filters:
-            sql = "update StackObjectThin join "+self.scratchDb.dvoDetectionTable +" using (objID, ippDetectID) set "+filter+"ippDetectID = ippDetectID \
+            if self.stackIDs[filter] <= 0: continue # stackIDs[filter] not set if we do not have the data
+
+            imageID = self.imageIDs[filter]
+
+            sql = "update StackObjectThin join "+self.scratchDb.dvoDetectionTable +" using (objID, ippObjID, ippDetectID) set "+filter+"ippDetectID = ippDetectID \
                   where " + self.scratchDb.dvoDetectionTable + ".imageID = " + str(imageID)
+
+            self.logger.debugPair("sql f", sql)
             self.scratchDb.execute(sql)
 
