public inbox for [email protected]
help / color / mirror / Atom feedFrom: David Raymond <[email protected]>
To: [email protected] <[email protected]>
Subject: RE: New user questions
Date: Wed, 14 Jul 2021 19:09:04 +0000
Message-ID: <AM0PR07MB5700896B94BF1CBB6ED1325987139@AM0PR07MB5700.eurprd07.prod.outlook.com> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
From https://www.psycopg.org/docs/sql.html
"The module contains objects and functions useful to generate SQL dynamically, in a convenient and safe way."
If there's nothing dynamic about the text of the query, then you don't really need to go through all the trouble of using all those classes. They're there in case you're getting unknown table names from a user, or building a query on the fly, etc. If you know the query right now, you can just put it into a text string, and call it good.
So your query2 might look something like this:
query = """select
p.lname,
p.fname,
p.loc_nbr,
p.job_title,
p.direct_phone,
p.active,
c.org_name,
l.loc_nbr,
l.loc_name,
a.act_date,
a.act_type,
a.notes,
a.next_contact
from
people as p
inner join companies as c on c.org_nbr = p.org_nbr
inner join locations as l on l.org_nbr = o.org_nbr and l.loc_nbr = p.loc_nbr
inner join contacts as a on a.person_nbr = p.person_nbr
where p.lname = %s and p.fname = %s
group by a.act_date order by a.act_date;"""
cur.execute(query, (lname_value, fname_value))
Note that I don't think this query of yours is gonna work as you've got a GROUP BY clause, and the SELECT list you have stuff that's not in the GROUP BY, and is not an aggregate.
view thread (10+ messages) latest in thread
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 using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: RE: New user questions
In-Reply-To: <AM0PR07MB5700896B94BF1CBB6ED1325987139@AM0PR07MB5700.eurprd07.prod.outlook.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox