From: | "brandon wallace" <nodnarb(at)gmx(dot)us> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Searching Postgresql Database with psycopg2 |
Date: | 2018-02-01 20:50:37 |
Message-ID: | trinity-629ff67a-1229-498d-88af-8c4019b21414-1517518236981@3c-app-mailcom-bs09 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div>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.</div>
<div>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.</div>
<div> </div>
<div>
<div>Here is my function.</div>
<div> </div>
<div>
<div>from tkinter import *<br/>
import psycopg2</div>
<div> </div>
<div>def search(title=None, isbn=None, year=0):<br/>
'''Search the database rows'''<br/>
conn = psycopg2.connect("dbname='books'")<br/>
cur = conn.cursor()<br/>
cur.execute("SELECT books.title, books.isbn, books.year FROM books WHERE books.title = title OR books.isbn = books.isbn OR books.year = year")<br/>
rows = cur.fetchone()<br/>
conn.close()<br/>
return rows</div>
<div> </div>
<div> </div>
<div> </div>
</div>
</div></div></body></html>
Attachment | Content-Type | Size |
---|---|---|
unknown_filename | text/html | 1.3 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Rob Sargent | 2018-02-01 20:52:51 | Re: Searching Postgresql Database with psycopg2 |
Previous Message | Joshua D. Drake | 2018-02-01 19:50:50 | What is your psql tip? |