Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ehLqt-0007yr-KL for pgsql-general@arkaria.postgresql.org; Thu, 01 Feb 2018 20:52:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ehLqs-0002IA-MB for pgsql-general@arkaria.postgresql.org; Thu, 01 Feb 2018 20:52:58 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ehLqs-0002Hz-7r for pgsql-general@lists.postgresql.org; Thu, 01 Feb 2018 20:52:58 +0000 Received: from mail-pl0-x236.google.com ([2607:f8b0:400e:c01::236]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ehLqp-0001Nu-Jc for pgsql-general@postgresql.org; Thu, 01 Feb 2018 20:52:57 +0000 Received: by mail-pl0-x236.google.com with SMTP id p5so4448256plo.12 for ; Thu, 01 Feb 2018 12:52:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc:message-id:references :to; bh=vDEuuUhOFuEWyUL94ArgjZoMzekhvd7W1NHZe0QX7bQ=; b=LSQUEO2L8nwoBr2OyOPEEbwwYSSg0cpeR+NOyRQSmlmeg2JS6MYgfynCrEzHm6OUKj cgsRMmrkP2xAn1p1uyllxXZtK7S+puCECd5iiR9evrYeKZgGzmh5Iy6P39tGX+qbOnxB BntuPTi51pHcygFEfcvwR1S8oYyj9FP8OErfkM2hb8R1Zdk0ZC2T7ikyL8bL+aMc0L// xA/v/Bvc39q8TW6ctNHqirRHYMrlmOiIQcr9GXpJZpz7Prhp3tiVY0vMsBd6Kh8BZOpo qzlLNu4+lMWaHJqpvTSoaD26TzZ4yDm+JBDRETJ9MATJNFd85IspNs154d2owKm7iZbM P8Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :message-id:references:to; bh=vDEuuUhOFuEWyUL94ArgjZoMzekhvd7W1NHZe0QX7bQ=; b=pGGTVB5arStyV7CbTSa6RbvoBBQHSj+IqDMsmCveKol5hBr+M6lZfSE7ePn2jhGmuC B0G68Vgw9wNCHxeMcIDQSBxG5TMs3t0pQQZ/TMCTz2KExEsbBm8/FxHp6hqbKsOz25Eg oAM/piFdXFrd6kbMveNsjAP95u9RGMO3ipjkDCJj8lGWp9eDcu8E3cI1IZR4vPow8tYf pyWyf7KWUiddqbVayTQwpWEETG7Zm70A0e4VQWLCcFPEKWnK19iR7QdHEhouKoB2lOgJ YTGHdwivkoC7oo9mx2duNfJZ0dxXnhhY5Vul27WgTSKaZ32GDYA2SW+yWBhcBc0WCj/I f8GA== X-Gm-Message-State: AKwxytfimGUt1+gnd4x3kvCw/YFJ2Bk1Hu0Ow4tVathRYUIa2cJ1zUTQ eQ6IywY/RQaNiiDDVfXY678= X-Google-Smtp-Source: AH8x226V5lIt2ZTxR0qcwXgDLFqJAMRjox/QHOOkhG43AuOmcJx4EysIaJgDbuaa9KFR7b7KNVPFzQ== X-Received: by 2002:a17:902:5309:: with SMTP id b9-v6mr23588804pli.152.1517518373353; Thu, 01 Feb 2018 12:52:53 -0800 (PST) Received: from kitselas.hci.utah.edu ([155.100.47.6]) by smtp.gmail.com with ESMTPSA id v81sm524851pfi.65.2018.02.01.12.52.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Feb 2018 12:52:52 -0800 (PST) Content-Type: multipart/alternative; boundary="Apple-Mail=_A75ECC51-D080-431A-B58A-8DF6DFDCFA33" Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: Re: Searching Postgresql Database with psycopg2 From: Rob Sargent X-Priority: 3 In-Reply-To: Date: Thu, 1 Feb 2018 13:52:51 -0700 Cc: "pgsql-general@postgresql.org" Message-Id: References: To: brandon wallace X-Mailer: Apple Mail (2.3273) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_A75ECC51-D080-431A-B58A-8DF6DFDCFA33 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Feb 1, 2018, at 1:50 PM, brandon wallace wrote: >=20 > 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. > =20 > =20 > Here is my function. > =20 > from tkinter import * > import psycopg2 > =20 > def search(title=3DNone, isbn=3DNone, year=3D0): > '''Search the database rows''' > conn =3D psycopg2.connect("dbname=3D'books'") > cur =3D conn.cursor() > cur.execute("SELECT books.title, books.isbn, books.year FROM books = WHERE books.title =3D title OR books.isbn =3D books.isbn OR books.year =3D= year") > rows =3D cur.fetchone() The =E2=80=9Cfetchone()=E2=80=9D proably has a lot to do with it > conn.close() > return rows > =20 > =20 > =20 --Apple-Mail=_A75ECC51-D080-431A-B58A-8DF6DFDCFA33 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
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=3DNone, isbn=3DNone, year=3D0):
    '''Search the database rows'''
    conn =3D psycopg2.connect("dbname=3D'books'")
    cur =3D conn.cursor()
    cur.execute("SELECT books.title, books.isbn, = books.year FROM books WHERE books.title =3D title OR books.isbn =3D = books.isbn OR books.year =3D year")
    rows =3D cur.fetchone()

The =E2=80=9Cfetchone()=E2=80=9D proably has a lot to do with = it

 =    conn.close()
    return rows
 
 
 

= --Apple-Mail=_A75ECC51-D080-431A-B58A-8DF6DFDCFA33--