pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rob Sargent <robjsargent@gmail.com>
To: brandon wallace <nodnarb@gmx.us>
Cc: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: Searching Postgresql Database with psycopg2
Date: Thu, 1 Feb 2018 13:52:51 -0700
Message-ID: <FFF7D277-E4A4-4DA6-8BC8-B7BB4DA01EE4@gmail.com> (raw)
In-Reply-To: <trinity-629ff67a-1229-498d-88af-8c4019b21414-1517518236981@3c-app-mailcom-bs09>
References: <trinity-629ff67a-1229-498d-88af-8c4019b21414-1517518236981@3c-app-mailcom-bs09>

> 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
>  
>  
>  

view thread (3+ messages)  latest in thread

Message-ID: <FFF7D277-E4A4-4DA6-8BC8-B7BB4DA01EE4@gmail.com>
Permalink:  ../FFF7D277-E4A4-4DA6-8BC8-B7BB4DA01EE4@gmail.com/
Also on:    postgresql.org/message-id/FFF7D277-E4A4-4DA6-8BC8-B7BB4DA01EE4@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: robjsargent@gmail.com, nodnarb@gmx.us
  Subject: Re: Searching Postgresql Database with psycopg2
  In-Reply-To: <FFF7D277-E4A4-4DA6-8BC8-B7BB4DA01EE4@gmail.com>
  References: <trinity-629ff67a-1229-498d-88af-8c4019b21414-1517518236981@3c-app-mailcom-bs09> <FFF7D277-E4A4-4DA6-8BC8-B7BB4DA01EE4@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox