Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pr3f0-00088l-9C for psycopg@arkaria.postgresql.org; Mon, 24 Apr 2023 21:23:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pr3ez-0002kJ-6X for psycopg@arkaria.postgresql.org; Mon, 24 Apr 2023 21:23:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pr3YQ-0003rs-2M for psycopg@lists.postgresql.org; Mon, 24 Apr 2023 21:16:58 +0000 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1pr3YM-004rfZ-QV for psycopg@postgresql.org; Mon, 24 Apr 2023 21:16:57 +0000 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-52160f75920so3640972a12.2 for ; Mon, 24 Apr 2023 14:16:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682371013; x=1684963013; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=yY8kbOw0Yy0usYOZPV74HoLMtC0FGIMG41jTJjh6k6o=; b=m0Aq0fDbro0iAK9WDgB5hzFYhMcxOmUtQSQaMHhuWena40jnX/xK6ZVL6V9y8UR1Fp 37HvxLprjwvA0/GFQb9gl16w8gP3dMyFYBiVJ2fuH0K6BpDTHDccglXgBWFZ0ngLYZYk wCstWeIjDQcmdnyjaKdH36z4p9Dl+6Y0DPyVqflfIClFVixtjvsZzcQeO5KzvS5yqtVe I7eFVoA2lM/st5hzjT0u2IJs1SJ4pt5q7E+vH6b5UVrlvYwjo2PcCfncpXy5Uy2IDY9e b9gbjk1rahYx2RUZoBzvuZDaJfSC3wHLeQjvs+z6uFb5AUAeHgALpo9kVpaIiMjkBFW0 UrTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682371013; x=1684963013; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=yY8kbOw0Yy0usYOZPV74HoLMtC0FGIMG41jTJjh6k6o=; b=XRCbfDas/CPOzm4yE867DvyrTuUeWnrMzBRl+CGJsWdaqXOq8H1ZB1PeIE8hxxqs7V HMuZD4ZTr1b9S2tziCBcZwZV8D2nDbCYjgPUw51mnaJhgANACUcMrA/9DCcaoPpymJ9A U11tXuQ1PXTOxY/Dd6yS/FIz4IHMRLaUEGvgfduJ1pMmucm8sWt/GTk76AyIef4NxYqj zz7ZZIyaLyaxfVQC2vLtA52HGkdDIAyQlXnjdvsVRhMRjMC1M7rRsd4ujpJeBiEV7EqN Qnr+5ln6S4kpHQzFH6h+ExDPX5ScbmbdGjDemn55VPz8D8UHAjV6ciwPTIv8rPhxUncu oiPA== X-Gm-Message-State: AAQBX9eg2tJdOJuLmLeTQkfjRfphXhawBretxBOjxVxKn6rWUXZgO6C2 ILzH0JCCDyFhFe2NYjjyWV1kUeVoi+Q23pqT0B5Qi0JZ X-Google-Smtp-Source: AKy350bavkrMhtayLQSnT1yndenaXcPunzst/RzTpkcsD8ok5y3cxaR83btgVFmJEGo3jtXiGx8po2G/JtPVVQWZM2o= X-Received: by 2002:a17:90a:f318:b0:246:b8a5:b702 with SMTP id ca24-20020a17090af31800b00246b8a5b702mr15488759pjb.29.1682371012748; Mon, 24 Apr 2023 14:16:52 -0700 (PDT) MIME-Version: 1.0 References: <237c1e3f-4118-6ffc-6e0b-ddce824f1f55@aklaver.com> <04fea413-8776-dd4e-7f0e-4b235b454f19@aklaver.com> <021e900b-53d0-c5a0-2750-a0fe60230e68@aklaver.com> In-Reply-To: <021e900b-53d0-c5a0-2750-a0fe60230e68@aklaver.com> From: "Michael P. McDonnell" Date: Mon, 24 Apr 2023 16:16:42 -0500 Message-ID: Subject: Re: Consecutive Inserts Freeze Execution of Psycopg3 To: Adrian Klaver Cc: psycopg@postgresql.org Content-Type: multipart/alternative; boundary="000000000000986d1605fa1b86c2" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000986d1605fa1b86c2 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hey Adrian - Just wanted to say thank you again for helping me with getting the session stuff structured appropriately. I actually found my issue and it turns out that while my code is suboptimal in a lot of ways - it was actually a separate database issue as a whole that I'm just now tracking down. Just thought you'd like to know that it was not a psycopg(3 or 2) issue, not a sqlalchemy issue, and it has something to do with how the queries seem to work. And the technical info (not an ask, just an inform) The queries are just an ETL from one table to another based on how the data needs to be accessed. If I trunc all the tables, and load the originating table - the first ETL works fine (table1 -> table2). However - when I then call the 2nd ETL from table2 to table3 - the query "freezes". I'm still looking into what that means and how to find what's going on. If I cancel the execution of that query and re-run the 2nd ETL (table2 to table3) - it runs in the amount of time I expected (2-3 seconds). So this fundamentally was never about a session, or commits, or anything else; those were working as expected - the query itself was just hung up in the server doing its "thing". Anywho - hopefully someone is googling and this pops up and helps them look at the problem differently. Have a great day. -Mike On Sun, Apr 23, 2023 at 8:20=E2=80=AFPM Adrian Klaver wrote: > On 4/23/23 18:06, Michael P. McDonnell wrote: > > So I appreciate you're trying to point to the official source of the > > documentation; but one place where FastAPI might be a place of > > This is the first mention of using FastAPI. > > > inspiration is the consistent building of a single use case example to > > show how one might do something more complex. Given the docs available = - > > I have no idea how I might take a dict and generate an UPDATE statement > > using the sql.SQL API you have. > > Some pseudo-code showing what you are trying to achieve would be useful. > > > > > And I'm genuinely not trying to nitpick here, I'm relatively new to > > Python and am more or less winging it and the documentation immediately > > available doesn't exactly spell out *all the things*; So again - thank > > you for your help in getting me over the original hump; I appreciate it= . > > It is tough for documentation to cover all possible user cases. I have > found the best way for me is to write a flow chart of what I want to do > and then search for the commands/code that gets me there. > > > > > On Sun, Apr 23, 2023 at 7:59=E2=80=AFPM Adrian Klaver > > wrote: > > > > On 4/23/23 17:26, Michael P. McDonnell wrote: > > > Thanks Adrian - > > > I appreciate it; and I've been pouring through documentation to > > try and > > > get to this point. > > > I can't help but feel I'm doing it "wrong" but no website I can > find > > > recently seems to have a "right" way of doing things that's > > reasonably > > > kept up. > > > It would be nice if "wrong" had a way of shooting me in the foot > > with > > > verbose errors or warnings. > > > > Start here: > > > > https://www.psycopg.org/psycopg3/docs/basic/index.html > > > > > > and work through the sections in order. > > > > > > > > -Mike > > > > > > On Sun, Apr 23, 2023 at 7:15=E2=80=AFPM Adrian Klaver > > > > > > >> wrote: > > > > > > On 4/23/23 14:55, Michael P. McDonnell wrote: > > > > That helped a ton, I don't understand why I've had to > > rewrite the > > > crap > > > > out of all of this to get it to work (dropping SqlAlchemy= , > > upgrading > > > > from psycopg2 to psycopg, etc...) but it's working now an= d > > I can > > > work > > > > around it. Thank you. > > > > > > Well: > > > > > > 1) SQLAlchemy is an ORM that tries to make all databases loo= k > > the same. > > > > > > 2) psycopg2 !=3D psycopg. For details see: > > > > > > https://www.psycopg.org/psycopg3/docs/basic/from_pg2.html > > > > > > > > > > > > > 3) It would have been more of a surprise if you did not have > > to change > > > anything. > > > > > > 4) And this > > > > > > with self.connection.cursor() as conn: > > > > > > was just plain wrong. You where trying to make a cursor be a > > connection > > > and that is not going to work. > > > > > > > > > > > > > > > > > > On Sun, Apr 23, 2023 at 4:25=E2=80=AFPM Adrian Klaver > > > > > >> > > > > > > > > > >>> wrote: > > > > > > > > On 4/23/23 13:45, Michael P. McDonnell wrote: > > > > > Python 3.10.6 > > > > > psycopg library 3.1.8 > > > > > > > > > > Running consecutive inserts sourced in files. > > > > > All inserts are of the same format: > > > > > > > > > > INSERT INTO _____ (field1, field2, field3) > > > > > SELECT field1, field2, field3 FROM ____, Join ___, > join > > > ___ etc... > > > > > > > > > > The code I've written is this: > > > > > > > > > > for qi in range(qlen): > > > > > query =3D queries[qi] > > > > > qparams =3D params[qi] > > > > > with self.connection.cursor() as conn= : > > > > > conn.execute(query, qparams) > > > > > > > > In above you are running the context manager(with) > > over the > > > cursor not > > > > the connection. This will not automatically commit th= e > > > transaction. You > > > > will need to either explicitly do connection.commit() > > or use > > > the with > > > > over the connection per: > > > > > > > > > > https://www.psycopg.org/psycopg3/docs/basic/transactions.html > > > > > > > > > > > > > > > > > > > > > > > > > >> > > > > > > > > > > > > > > When I run the queries in dbeaver - the first quer= y > > takes > > > 120s (it's > > > > > 1.9M rows), the second query takes 2s (7000 rows). > > > > > When I run the queries in python - it freezes on t= he > > > second query. > > > > > > > > > > Any guidance on how to attack this would be awesom= e > > as I have > > > > re-written > > > > > my code a dozen times and am just slinging mud to > > see what > > > sticks. > > > > > > > > -- > > > > Adrian Klaver > > > > adrian.klaver@aklaver.com > > > > > > > > > >> > > > > > > > > > > -- > > > Adrian Klaver > > > adrian.klaver@aklaver.com > > >> > > > > > > > -- > > Adrian Klaver > > adrian.klaver@aklaver.com > > > > -- > Adrian Klaver > adrian.klaver@aklaver.com > > --000000000000986d1605fa1b86c2 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hey Adrian -=C2=A0
Just wanted to say thank you again = for helping me with getting the session=C2=A0stuff structured appropriately= . I actually found my issue and it turns out that while my code is suboptim= al in a lot of ways - it was actually a separate database issue as a whole = that I'm just now tracking down.
Just thought you'd like = to know that it was not a psycopg(3 or 2) issue, not a sqlalchemy issue, an= d it has something to do with how the queries seem to work.
<= br>
And the technical info (not an ask, just an inform)
The queries are just an ETL from one table to another based on how the dat= a needs to be accessed. If I trunc all the tables, and load the originating= table - the first ETL works fine (table1 -> table2).=C2=A0
However -= when I then call the 2nd ETL from table2 to table3 - the query "freez= es". I'm still looking into what that means and how to find what&#= 39;s going on.
If I cancel the execution of that query and re-run= the 2nd ETL (table2 to table3) - it runs in the amount of time I expected = (2-3 seconds).=C2=A0

So this fundamentally was nev= er about a session, or commits, or anything else; those were working as exp= ected - the query itself was just hung up in the server doing its "thi= ng".=C2=A0

Anywho - hopefully someone is = googling and this pops up and helps them look at the problem differently. H= ave a great day.
-Mike

=
On Sun, Apr 23, 2023 at 8:20=E2=80=AF= PM Adrian Klaver <adrian.kl= aver@aklaver.com> wrote:
On 4/23/23 18:06, Michael P. McDonnell wrote:
> So I appreciate you're trying to point to the official source of t= he
> documentation; but one place where FastAPI might be a place of

This is the first mention of using FastAPI.

> inspiration is the consistent building of a single use case example to=
> show how one might do something more complex. Given the docs available= -
> I have no idea how I might take a dict and generate an UPDATE statemen= t
> using the sql.SQL API you have.

Some pseudo-code showing what you are trying to achieve would be useful.
>
> And I'm genuinely not trying to nitpick here, I'm relatively n= ew to
> Python and am more or less winging it and the documentation immediatel= y
> available doesn't exactly spell out *all the things*; So again - t= hank
> you for your help in getting me over the original hump; I appreciate i= t.

It is tough for documentation to cover all possible user cases. I have
found=C2=A0 the best way for me is to write a flow chart of what I want to = do
and then search for the commands/code that gets me there.

>
> On Sun, Apr 23, 2023 at 7:59=E2=80=AFPM Adrian Klaver <adrian.klaver@aklaver.co= m
> <mailto:adrian.klaver@aklaver.com>> wrote:
>
>=C2=A0 =C2=A0 =C2=A0On 4/23/23 17:26, Michael P. McDonnell wrote:
>=C2=A0 =C2=A0 =C2=A0 > Thanks Adrian -
>=C2=A0 =C2=A0 =C2=A0 > I appreciate it; and I've been pouring th= rough documentation to
>=C2=A0 =C2=A0 =C2=A0try and
>=C2=A0 =C2=A0 =C2=A0 > get to this point.
>=C2=A0 =C2=A0 =C2=A0 > I can't help but feel I'm doing it &q= uot;wrong" but no website I can find
>=C2=A0 =C2=A0 =C2=A0 > recently seems to have a "right" wa= y of doing things that's
>=C2=A0 =C2=A0 =C2=A0reasonably
>=C2=A0 =C2=A0 =C2=A0 > kept up.
>=C2=A0 =C2=A0 =C2=A0 > It would be nice if "wrong" had a w= ay of shooting me in the foot
>=C2=A0 =C2=A0 =C2=A0with
>=C2=A0 =C2=A0 =C2=A0 > verbose errors or warnings.
>
>=C2=A0 =C2=A0 =C2=A0Start here:
>
>=C2=A0 =C2=A0 =C2=A0https://www.psycopg.or= g/psycopg3/docs/basic/index.html
>=C2=A0 =C2=A0 =C2=A0<https://www.psycop= g.org/psycopg3/docs/basic/index.html>
>
>=C2=A0 =C2=A0 =C2=A0and work through the sections in order.
>
>=C2=A0 =C2=A0 =C2=A0 >
>=C2=A0 =C2=A0 =C2=A0 > -Mike
>=C2=A0 =C2=A0 =C2=A0 >
>=C2=A0 =C2=A0 =C2=A0 > On Sun, Apr 23, 2023 at 7:15=E2=80=AFPM Adria= n Klaver
>=C2=A0 =C2=A0 =C2=A0<adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com&= gt;
>=C2=A0 =C2=A0 =C2=A0 > <mailto:adrian.klaver@aklaver.com
>=C2=A0 =C2=A0 =C2=A0<mailto:adrian.klaver@aklaver.com>>> wrote:
>=C2=A0 =C2=A0 =C2=A0 >
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0On 4/23/23 14:55, Michael = P. McDonnell wrote:
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 > That helped a ton, I= don't understand why I've had to
>=C2=A0 =C2=A0 =C2=A0rewrite the
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0crap
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 > out of all of this t= o get it to work (dropping SqlAlchemy,
>=C2=A0 =C2=A0 =C2=A0upgrading
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 > from psycopg2 to psy= copg, etc...) but it's working now and
>=C2=A0 =C2=A0 =C2=A0I can
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0work
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 > around it. Thank you= .
>=C2=A0 =C2=A0 =C2=A0 >
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0Well:
>=C2=A0 =C2=A0 =C2=A0 >
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A01) SQLAlchemy is an ORM th= at tries to make all databases look
>=C2=A0 =C2=A0 =C2=A0the same.
>=C2=A0 =C2=A0 =C2=A0 >
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A02) psycopg2 !=3D psycopg. = For details see:
>=C2=A0 =C2=A0 =C2=A0 >
>=C2=A0 =C2=A0 =C2=A0 > https://www.p= sycopg.org/psycopg3/docs/basic/from_pg2.html
>=C2=A0 =C2=A0 =C2=A0<https://www.psy= copg.org/psycopg3/docs/basic/from_pg2.html>
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0<https://www.psycopg.org/psycopg3/docs/basic/from_pg2.html >=C2=A0 =C2=A0 =C2=A0<https://www.psy= copg.org/psycopg3/docs/basic/from_pg2.html>>
>=C2=A0 =C2=A0 =C2=A0 >
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A03) It would have been more= of a surprise if you did not have
>=C2=A0 =C2=A0 =C2=A0to change
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0anything.
>=C2=A0 =C2=A0 =C2=A0 >
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A04) And this
>=C2=A0 =C2=A0 =C2=A0 >
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0with self.connection.curso= r() as conn:
>=C2=A0 =C2=A0 =C2=A0 >
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0was just plain wrong. You = where trying to make a cursor be a
>=C2=A0 =C2=A0 =C2=A0connection
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0and that is not going to w= ork.
>=C2=A0 =C2=A0 =C2=A0 >
>=C2=A0 =C2=A0 =C2=A0 >
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 > On Sun, Apr 23, 2023= at 4:25=E2=80=AFPM Adrian Klaver
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0<adrian.klaver@aklaver.com <= mailto:adria= n.klaver@aklaver.com>
>=C2=A0 =C2=A0 =C2=A0<mailto:adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.c= om>>
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 > <mailto:adrian.klaver@aklav= er.com
>=C2=A0 =C2=A0 =C2=A0<mailto:adrian.klaver@aklaver.com>
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0<mailto:adrian.klaver@aklaver.com
>=C2=A0 =C2=A0 =C2=A0<mailto:
adrian.klaver@aklaver.com>>>> wrote:=
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0O= n 4/23/23 13:45, Michael P. McDonnell wrote:
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 = > Python 3.10.6
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 = > psycopg library 3.1.8
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 = >
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 = > Running consecutive inserts sourced in files.
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 = > All inserts are of the same format:
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 = >
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 = > INSERT INTO _____ (field1, field2, field3)
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 = > SELECT field1, field2, field3 FROM ____, Join ___, join
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0___ etc...
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 = >
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 = > The code I've written is this:
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 = >
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 = > for qi in range(qlen):
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 = >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 query =3D queries[qi]<= br> >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 = >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 qparams =3D params[qi]=
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 = >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 with self.connection.c= ursor() as conn:
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 = >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 conn.exe= cute(query, qparams)
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0I= n above you are running the context manager(with)
>=C2=A0 =C2=A0 =C2=A0over the
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0cursor not
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0t= he connection. This will not automatically commit the
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0transaction. You
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0w= ill need to either explicitly do connection.commit()
>=C2=A0 =C2=A0 =C2=A0or use
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0the with
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0o= ver the connection per:
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >
>=C2=A0 =C2=A0 =C2=A0https://www.psy= copg.org/psycopg3/docs/basic/transactions.html
>=C2=A0 =C2=A0 =C2=A0<https://www= .psycopg.org/psycopg3/docs/basic/transactions.html>
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0
>=C2=A0 =C2=A0 =C2=A0 =C2=A0<http= s://www.psycopg.org/psycopg3/docs/basic/transactions.html
>=C2=A0 =C2=A0 =C2=A0<https://www= .psycopg.org/psycopg3/docs/basic/transactions.html>>
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0
>=C2=A0 =C2=A0 =C2=A0 =C2=A0<http= s://www.psycopg.org/psycopg3/docs/basic/transactions.html
>=C2=A0 =C2=A0 =C2=A0<https://www= .psycopg.org/psycopg3/docs/basic/transactions.html>
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0
>=C2=A0 =C2=A0 =C2=A0 =C2=A0<http= s://www.psycopg.org/psycopg3/docs/basic/transactions.html
>=C2=A0 =C2=A0 =C2=A0<https://www= .psycopg.org/psycopg3/docs/basic/transactions.html>>>
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 = >
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 = > When I run the queries in dbeaver - the first query
>=C2=A0 =C2=A0 =C2=A0takes
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0120s (it's
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 = > 1.9M rows), the second query takes 2s (7000 rows).
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 = > When I run the queries in python - it freezes on the
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0second query.
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 = >
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 = > Any guidance on how to attack this would be awesome
>=C2=A0 =C2=A0 =C2=A0as I have
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0r= e-written
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 = > my code a dozen times and am just slinging mud to
>=C2=A0 =C2=A0 =C2=A0see what
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0sticks.
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0-= -
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0A= drian Klaver
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 > adrian.klaver@aklaver.com >=C2=A0 =C2=A0 =C2=A0<mailto:adrian.klaver@aklaver.com> <mailto:adrian.klaver@aklav= er.com
>=C2=A0 =C2=A0 =C2=A0<mailto:adrian.klaver@aklaver.com>>
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0<mailto:adrian.klaver@aklaver.com
>=C2=A0 =C2=A0 =C2=A0<mailto:
adrian.klaver@aklaver.com> <mailto:adrian.klaver@aklav= er.com
>=C2=A0 =C2=A0 =C2=A0<mailto:adrian.klaver@aklaver.com>>>
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 >
>=C2=A0 =C2=A0 =C2=A0 >
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0--
>=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0Adrian Klaver
>=C2=A0 =C2=A0 =C2=A0 > adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>
>=C2=A0 =C2=A0 =C2=A0<mailto:
adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.c= om>>
>=C2=A0 =C2=A0 =C2=A0 >
>
>=C2=A0 =C2=A0 =C2=A0--
>=C2=A0 =C2=A0 =C2=A0Adrian Klaver
>=C2=A0 =C2=A0 =C2=A0adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com><= br> >

--
Adrian Klaver
adrian.klave= r@aklaver.com

--000000000000986d1605fa1b86c2--