0

I was trying to dump my PostgreSQL database created via SQLalchemy using python script. Though I have successfully created a database and all the data are getting inserted via web parsing in the ORM I have mapped with. But when I am trying to take a dump for all my insert queries using this

tab = Table(table.__tablename__, MetaData())
        x = tab.insert().compile(
            dialect=postgresql.dialect(),
            compile_kwargs={"literal_binds": True},
        )
        logging.info(f"{x}")

I am adding values using ORM like this:

   for value in vertex_type_values:
        data = table(
            Type=value["type"],
            Name=value["name"],
            SizeX=value["size_x"],
            SizeY=value["size_y"],
            SizeZ=value["size_z"],
        )
        session.add(data)
   session.commit()

here table is the model which i have designed and imported from my local library and vertex_type_values which I have extracted and yield in my script I am getting the output as

INSERT INTO <tablename> DEFAULT VALUES

So my question is how to get rid of Default Values and get actual values so that I can directly use insert command if my DB crash anytime? I need to know raw SQL for insert command

Harshit
  • 1
  • 2
  • What actual values? – Ilja Everilä Apr 02 '20 at 21:06
  • Does this answer your question? [SQLAlchemy: print the actual query](https://stackoverflow.com/questions/5631078/sqlalchemy-print-the-actual-query) – SuperShoot Apr 03 '20 at 00:03
  • No @SuperShoot it didn't resolve. In that, they are compiling statements, but in my case, I am not having an exact statement. But it will be something similar. I have added how I am inserting values in DB – Harshit Apr 03 '20 at 09:21
  • @lija, values could be anything.. like **Type = abc, Name= "xyz", SizeX =1, SizeY =43, SizeZ =5** – Harshit Apr 03 '20 at 09:23

0 Answers0