def insertFacts(self):
        accsId = self.accessionId
        if self.accessionPreviouslyInDB:
            self.showStatus("deleting prior facts of this accession")
            # remove prior facts
            self.execute("DELETE FROM fact WHERE fact.accession_id = {};".format(accsId), 
                         close=False, fetch=False)
            self.execute("DELETE from unit_measure "
                         "USING unit "
                         "WHERE unit.accession_id = {0} AND unit_measure.unit_id = unit.unit_id;".format(accsId), 
                         close=False, fetch=False)
            self.execute("DELETE from unit WHERE unit.accession_id = {0};".format(accsId), 
                         close=False, fetch=False)
            self.execute("DELETE from context WHERE context.accession_id = {0};".format(accsId), 
                         close=False, fetch=False)
        self.showStatus("insert facts")
        # units
        table = self.getTable('unit', 'unit_id', 
                              ('accession_id', 'unit_xml_id'), 
                              ('accession_id', 'unit_xml_id'), 
                              tuple((accsId,
                                     unitId)
                                    for unitId in self.modelXbrl.units.keys()))
        self.unitId = dict(((_accsId, xmlId), id)
                           for id, _accsId, xmlId in table)
        # measures
        table = self.getTable('unit_measure', 'unit_measure_id', 
                              ('unit_id', 'qname_id', 'location_id'), 
                              ('qname_id', 'location_id'), 
                              tuple((self.unitId[(accsId,unit.id)],
                                     self.qnameId[measure],
                                     1 if (not unit.measures[1]) else (i + 1))
                                    for unit in self.modelXbrl.units.values()
                                    for i in range(2)
                                    for measure in unit.measures[i]))
        #table = self.getTable('enumeration_measure_location', 'enumeration_measure_location_id', 
        #                      ('description',), 
        #                      ('description',),
        #                      (('measure',), ('numerator',), ('denominator',)))
        # context
        table = self.getTable('context', 'context_id', 
                              ('accession_id', 'period_start', 'period_end', 'period_instant', 'specifies_dimensions', 'context_xml_id', 'entity_scheme', 'entity_identifier'), 
                              ('accession_id', 'context_xml_id'), 
                              tuple((accsId,
                                     cntx.startDatetime if cntx.isStartEndPeriod else None,
                                     cntx.endDatetime if cntx.isStartEndPeriod else None,
                                     cntx.instantDatetime if cntx.isInstantPeriod else None,
                                     bool(cntx.qnameDims),
                                     cntx.id,
                                     cntx.entityIdentifier[0],
                                     cntx.entityIdentifier[1])
                                    for cntx in self.modelXbrl.contexts.values()))
        self.cntxId = dict(((_accsId, xmlId), id)
                           for id, _accsId, xmlId in table)
        # context_dimension
        values = []
        for cntx in self.modelXbrl.contexts.values():
            for dim in cntx.qnameDims.values():
                values.append((self.cntxId[(accsId,cntx.id)],
                               self.qnameId[dim.dimensionQname],
                               self.qnameId.get(dim.memberQname), # may be None
                               self.qnameId.get(dim.typedMember.qname) if dim.isTyped else None,
                               False, # not default
                               dim.contextElement == "segment",
                               dim.typedMember.stringValue if dim.isTyped else None))
            for dimQname, memQname in self.modelXbrl.qnameDimensionDefaults.items():
                if dimQname not in cntx.qnameDims:
                    values.append((self.cntxId[(accsId,cntx.id)],
                                   self.qnameId[dimQname],
                                   self.qnameId[memQname],
                                   None,
                                   True, # is default
                                   True, # ambiguous and irrelevant for the XDT model
                                   None))
        table = self.getTable('context_dimension', 'context_dimension_id', 
                              ('context_id', 'dimension_qname_id', 'member_qname_id', 'typed_qname_id', 'is_default', 'is_segment', 'typed_text_content'), 
                              ('context_id', 'dimension_qname_id', 'member_qname_id'), # shouldn't typed_qname_id be here?  not good idea because it's not indexed in XBRL-US DDL
                              values)
        # facts
        def insertFactSet(modelFacts, tupleFactId):
            table = self.getTable('fact', 'fact_id', 
                                  ('accession_id', 'tuple_fact_id', 'context_id', 'unit_id', 'element_id', 'effective_value', 'fact_value', 
                                   'xml_id', 'precision_value', 'decimals_value', 
                                   'is_precision_infinity', 'is_decimals_infinity', ), 
                                  ('accession_id', 'xml_id'), 
                                  tuple((accsId,
                                         tupleFactId,
                                         self.cntxId.get((accsId,fact.contextID)),
                                         self.unitId.get((accsId,fact.unitID)),
                                         self.conceptElementId(fact.concept),
                                         roundValue(fact.value, fact.precision, fact.decimals) if fact.isNumeric and not fact.isNil else None,
                                         fact.value,
                                         elementFragmentIdentifier(fact),
                                         fact.xAttributes['precision'].xValue if ('precision' in fact.xAttributes and isinstance(fact.xAttributes['precision'].xValue,int)) else None,
                                         fact.xAttributes['decimals'].xValue if ('decimals' in fact.xAttributes and isinstance(fact.xAttributes['decimals'].xValue,int)) else None,
                                         'precision' in fact.xAttributes and fact.xAttributes['precision'].xValue == 'INF',
                                         'decimals' in fact.xAttributes and fact.xAttributes['decimals'].xValue == 'INF',
                                         )
                                        for fact in modelFacts))
            factId = dict((xmlId, id)
                          for id, _accsId, xmlId in table)
            for fact in modelFacts:
                if fact.isTuple:
                    insertFactSet(fact.modelTupleFacts, 
                                  factId[elementFragmentIdentifier(fact)])
        insertFactSet(self.modelXbrl.facts, None)
        # hashes
dataset/ETHPy150Open Arelle/Arelle/arelle/plugin/xbrlDB/XbrlPublicPostgresDB.py/XbrlPostgresDatabaseConnection.insertFacts/original