使用python postgres的输入数据进行搜索和打印
我试图制作一个应用程序,用户输入一个项目,搜索数据库并打印结果使用python postgres的输入数据进行搜索和打印,python,database,postgresql,Python,Database,Postgresql,我试图制作一个应用程序,用户输入一个项目,搜索数据库并打印结果 book = input("Give me book-name") cur.execute('''select isbn,tittle_books,name_publisher,book_available from books where book_available = %s ''',(book,)) print("\nSelecting rows from books table using cu
book = input("Give me book-name")
cur.execute('''select isbn,tittle_books,name_publisher,book_available from books where book_available = %s ''',(book,))
print("\nSelecting rows from books table using cursor.fetchall")
records = cur.fetchall()
print("\nPrint each row and it's columns values\n")
for row in records:
print("isbn =", row[0],)
print("tittle_books = ", row[1])
print("name_publisher = ", row[2])
print("book_available = ", row[3],"\n---------------")
上面的代码没有显示结果我看到的一个问题是您正在进行精确的查找,
book\u available=%s
。因此,如果从输入返回的图书名称不准确,您将发现任何内容。如果您提供了一个数据输入、实际生成的查询以及Postgres日志中显示的任何可能错误的示例,则解决此问题会更容易。这是一个结果,请给我书名Raven使用游标从books表中选择行。fetchall打印每一行及其列值PostgreSQL连接已关闭,但是在books
表中是否存在Raven的确切名称?换句话说,在psql
中,是否选择isbn、title\u books、name\u publisher、book\u available from books where book\u available='Raven'
返回任何内容?是的,它在我的数据库中,因此我不会得到任何内容。我不明白。在psql
中运行查询时是否得到结果?