0
   cur.execute("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE 
   TABLE_NAME LIKE [{}]".format(tableName))

This is my code, but table names are not displaying. Maybe the problem here is in format.

3
  • are you looking for table names or columns names ? tables are available with "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE %s" Commented Nov 3, 2017 at 18:52
  • I want column name from the table which is stored already in a variable.Thats y : SELECT column_name FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME LIKE %s Commented Nov 3, 2017 at 19:00
  • so the answer below is the solution, but if you get errors with another part of code, you should add it, or post another question Commented Nov 3, 2017 at 19:05

1 Answer 1

1

Use parameters! In Python, this looks like

cur.execute("""
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME LIKE ?""", (tableName))

Some databases may prefer %s rather than ?.

Sign up to request clarification or add additional context in comments.

1 Comment

Once i am using this syntax, the rest of the code isnt working.It works if codecur.execute(""" SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS)code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.