Skip to content
Advertisement

Python ibm_db equivalent of db2look

SO I am using ibm_db library for fetch necessary information. Now I want to get the full table creation script along with index and all. I can see there is one db2look command to generate the same

db2look -d some_db -z xxxx -t xxxx -e -i xxxx-w xxxx -o script.sql

Is there an equivalent thing in ibm_db?

Advertisement

Answer

No, there is not an exact equivalent in the python ibm_db for the db2look tool.

Alternative approaches exist.

Nothing (except suitable authorities/permissions) prevents you from running a stored procedure that exececutes (i.e. shells out to) db2look on the database-server and return its output to the python script.

If the workstation running python ibm_db also has the Db2 fat client installed, then python can directly run db2look as long as your Db2 client has the relevant database(s) catalogued.

You can also use python to execute an undocumented DB2-LUW stored procedure (sysproc.DB2LK_GENERATE_DDL()) as described in this answer, subject to your account having relevant rights.

You can also write your own queries for the catalog views (i.e. re-invent the wheel), in order to generate the DDL, which lets you do whatever you want.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement