How to write Partitions to Postgres using foreachpartition (Pyspark) : I am new to Spark and trying to wite df partitions to Postgres
here is my code :
**#csv_new is a df with nearly 40 million rows and 6 coloumns**

    csv_new .foreachPartition(callback)# there are 19204 partitions
    def callback(iterator):
       print(iterator)
# the print gives me itertools.chain object 


but when Writing to db gives an error

    iterator.write.option("numPartitions", count).option("batchsize", 
     1000000).jdbc(url=url, table="table_name", mode=mode, 
      properties=properties) 
*AttributeError: 'itertools.chain' object has no attribute 'write'
# mode is append and properties are set 

Any leads on how to to write the df partition to db

