public inbox for [email protected]
help / color / mirror / Atom feedFrom: Rich Shepard <[email protected]>
To: [email protected]
Subject: Re: New user questions
Date: Wed, 14 Jul 2021 10:35:54 -0700 (PDT)
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
On Tue, 13 Jul 2021, Adrian Klaver wrote:
> Then you want to take a look at this:
> https://www.psycopg.org/docs/sql.html
Adrian,
Based on pages 1-2 of that doc I've re-written one each of an insert and
select query. When they are correct I'll do the rest of the insert and
select queries.
Query 1:
cur.execute(
sql.SQL("insert into {} values (%s, %s, %s, %s, %s)"
.format(sql.identifier('contacts')),
[c.nbr, a.date, a.type, a.notes, a.next]))
Query 2:
query = sql.SQL("select {fields} from {tables}").format(
fields = sql.SQL(',').join([
sql.identifier('p.lname'),
sql.identifier('p.fname'),
sql.identifier('p.loc_nbr'),
sql.identifier('p.job_title'),
sql.identifier('p.direct_phone'),
sql.identifier('p.active'),
sql.identifier('c.org_name'),
sql.identifier('l.loc_nbr'),
sql.identifier('l.loc_name'),
sql.identifier('a.act_date'),
sql.identifier('a.act_type'),
sql.identifier('a.notes'),
sql.identifier('a.next_contact'),
])
tables = sql.SQL(',').join([
sql.identifier('people as p'),
sql.identifier('companies as c on c.org_nbr = p.org_nbr'),
sql.identifier('locations as l on l.org_nbr = o.org_nbr and l.loc_nbr = p.loc_nbr'),
sql.identifier('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", (lname,fname))
> For an UPDATE example see my answer to this Stack Overflow question:
> https://stackoverflow.com/questions/68321746/how-to-create-a-dynamic-update-query-in-sql-using-pytho...
I'll read this again in close detail after I understand how to write insert
and select queries.
Regards,
Rich
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: <[email protected]>
* 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