Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用python postgres的输入数据进行搜索和打印_Python_Database_Postgresql - Fatal编程技术网

使用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
中运行查询时是否得到结果?