Re: Searching Postgresql Database with psycopg2

Поиск
Список
Период
Сортировка
От Rob Sargent
Тема Re: Searching Postgresql Database with psycopg2
Дата
Msg-id FFF7D277-E4A4-4DA6-8BC8-B7BB4DA01EE4@gmail.com
обсуждение исходный текст
Список pgsql-general
On Feb 1, 2018, at 1:50 PM, brandon wallace <nodnarb@gmx.us> wrote:

I have created a function to search a Postgresql database but it only pulls up the first row of the database no matter what value I search for. Why would it only pull up the first row of the database? I am using Psycopg2 2.6 and Python 3.5.
All my other functions to update, add, delete, view all rows are working fine. I am able to run queries on the database and only pull up the rows I need using psql command line no problem.
 
 
Here is my function.
 
from tkinter import *
import psycopg2
 
def search(title=None, isbn=None, year=0):
    '''Search the database rows'''
    conn = psycopg2.connect("dbname='books'")
    cur = conn.cursor()
    cur.execute("SELECT books.title, books.isbn, books.year FROM books WHERE books.title = title OR books.isbn = books.isbn OR books.year = year")
    rows = cur.fetchone()

The “fetchone()” proably has a lot to do with it

     conn.close()
    return rows
 
 
 

В списке pgsql-general по дате отправления:

Предыдущее
От: "Joshua D. Drake"
Дата:
Сообщение: What is your psql tip?
Следующее
От: David Kohn
Дата:
Сообщение: Re: Searching Postgresql Database with psycopg2