the DRY approach would be to move METADATA_MAPPING up and change the sql to IN METADATA_MAPPING.keys() ... (but you'll have to change the [] to () somehow.