def insertElements(self):
        self.showStatus("insert elements")
        
        filingDocumentConcepts = set()
        existingDocumentUsedConcepts = set()
        for concept in self.modelXbrl.qnameConcepts.values():
            if concept.modelDocument.uri not in self.existingDocumentIds:
                filingDocumentConcepts.add(concept)
            elif concept in self.conceptsUsed:
                existingDocumentUsedConcepts.add(concept)
                
        table = self.getTable('element', 'element_id', 
                              ('qname_id', 'datatype_qname_id', 'xbrl_base_datatype_qname_id', 'balance_id',
                               'period_type_id', 'substitution_group_qname_id', 'abstract', 'nillable',
                               'document_id', 'is_numeric', 'is_monetary'), 
                              ('qname_id',), 
                              tuple((self.qnameId[concept.qname],
                                     self.qnameId.get(concept.typeQname), # may be None
                                     self.qnameId.get(concept.baseXbrliTypeQname
                                                      if not isinstance(concept.baseXbrliTypeQname, list)
                                                      else concept.baseXbrliTypeQname[0]
                                                      ), # may be None or may be a list for a union
                                     {'debit':1, 'credit':2, None:None}[concept.balance],
                                     {'instant':1, 'duration':2, 'forever':3, None:0}[concept.periodType],
                                     self.qnameId.get(concept.substitutionGroupQname), # may be None
                                     concept.isAbstract, 
                                     concept.isNillable,
                                     self.documentIds[concept.modelDocument.uri],
                                     concept.isNumeric,
                                     concept.isMonetary)
                                    for concept in filingDocumentConcepts)
                             )
        self.elementId = dict((qnameId, elementId)  # indexed by qnameId, not by qname value
                              for elementId, qnameId in table)
        filingDocumentConcepts.clear() # dereference
        
        # get existing element IDs
        if existingDocumentUsedConcepts:
            conceptQnameIds = []
            for concept in existingDocumentUsedConcepts:
                conceptQnameIds.append(str(self.qnameId[concept.qname]))
            results = self.execute("SELECT element_id, qname_id FROM element WHERE qname_id IN (" +
                                   ', '.join(conceptQnameIds) + ");")
            for elementId, qnameId in results:
                self.elementId[qnameId] = elementId
        existingDocumentUsedConcepts.clear() # dereference
dataset/ETHPy150Open Arelle/Arelle/arelle/plugin/xbrlDB/XbrlPublicPostgresDB.py/XbrlPostgresDatabaseConnection.insertElements/original