Im learning to "python 2.7"

I've created a postgres db, but foolishly I renamed some of the descriptions with a *.

Is there a way to select the data using the * operator in the search string - I've tried

*name, /*name, "*name" ,'*name'

Many thanks

import psycopg2
db = psycopg2.connect(database='Database', user="postgres", host="192.168.0.1", password="xyz")
cursor = db.cursor()
cursor.execute("SELECT *  FROM table_name WHERE description = '*name'")
dbinfo = cursor.fetchone()
print dbinfo[0]

Edit I change the code above to include " ' ' " and print dbinfo[0]

Dont get an error without the 'print' But with the 'print' I get the error..

TypeError: 'NoneType' object has no attribute '__getitem__'
有帮助吗?

解决方案 2

My apologies to all I have discovered my mistake

in an earlier part of the program when the "description = *name" got saved, it saved a load of whitespace after the name, hence my search string couldn't find a match!

其他提示

This is so bad in so many ways that it's worth the effort to go back and change the column names to more standard instead of potentially confusing every user of your db and making it very difficult to write proper sql against it.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top