pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rob Sargent <robjsargent@gmail.com>
To: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Cc: Ron <ronljohnsonjr@gmail.com>
Cc: Ken Tanzer <ken.tanzer@gmail.com>
Subject: Re: How to write such a query
Date: Fri, 18 Sep 2020 13:51:51 -0600
Message-ID: <1C9CA252-1689-4F69-BC66-CDCDFE46FE87@gmail.com> (raw)
In-Reply-To: <CAD3a31XmfCqz-p7Ssky53U7m4fkL0RHGZyM=RVfD5+K-RZ69Gw@mail.gmail.com>
References: <CA+FnnTzwZv4x8cuLWYBoOJecaXS1qFOaLPrkopF-LWkKoBNP1w@mail.gmail.com>
	<CAK8Y=HV826Qw-1tPNOZwCnz+sNqYio8tvGDFW+4jPwL4NRDfKg@mail.gmail.com>
	<CA+FnnTw9om1qTBSpzb9tsZWqj0r6ebpENj-jCtxmvhDAoRBdEA@mail.gmail.com>
	<912dd33c-c837-a226-111f-413fcb7321c1@aklaver.com>
	<CA+FnnTwPFb2ru4JkJdbyGo9+9U+bOPRTAt991qhqSMx7adrbEQ@mail.gmail.com>
	<f3ac3c95-4935-6662-27ad-a025093b5af3@gmail.com>
	<CAD3a31XmfCqz-p7Ssky53U7m4fkL0RHGZyM=RVfD5+K-RZ69Gw@mail.gmail.com>



> On Sep 18, 2020, at 1:45 PM, Ken Tanzer <ken.tanzer@gmail.com> wrote:
> 
> > How to find what the primary key (or UNIQUE identifier) value is
> > for row 5 in the recordset?
> 
> You're missing the point: as mentioned before, there is no "row 5". To 
> update the 5th record that you've fetched, you increment a counter each time 
> you fetch a row, and when you read #5, do an UPDATE X SET field1 = 'blarg' 
> WHERE id = <thekeyvalue>;
> 
> 
> It seems worth mentioning for benefit of the OPs question that there _is_ a way to get a row number within a result set.  Understanding and making good use of that is an additional matter.
> 
> SELECT X.field1, Y.field2,row_number() OVER ()  from X, Y WHERE X.id = Y.id -- ORDER BY ____?
> 
> That row number is going to depend on the order of the query, so it might or might not have any meaning.  But if you queried with a primary key and a row number, you could then tie the two together and make an update based on that.

If “row 5” as seen by the OP has no distinguishing characteristic directing OP to edit that tuple then he’s in a world of hurt, well beyond the reach of anyone here.=

view thread (36+ messages)  latest in thread

Message-ID: <1C9CA252-1689-4F69-BC66-CDCDFE46FE87@gmail.com>
Permalink:  ../1C9CA252-1689-4F69-BC66-CDCDFE46FE87@gmail.com/
Also on:    postgresql.org/message-id/1C9CA252-1689-4F69-BC66-CDCDFE46FE87@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, ronljohnsonjr@gmail.com, ken.tanzer@gmail.com
  Subject: Re: How to write such a query
  In-Reply-To: <1C9CA252-1689-4F69-BC66-CDCDFE46FE87@gmail.com>
  References: <CA+FnnTzwZv4x8cuLWYBoOJecaXS1qFOaLPrkopF-LWkKoBNP1w@mail.gmail.com> <CAK8Y=HV826Qw-1tPNOZwCnz+sNqYio8tvGDFW+4jPwL4NRDfKg@mail.gmail.com> <CA+FnnTw9om1qTBSpzb9tsZWqj0r6ebpENj-jCtxmvhDAoRBdEA@mail.gmail.com> <912dd33c-c837-a226-111f-413fcb7321c1@aklaver.com> <CA+FnnTwPFb2ru4JkJdbyGo9+9U+bOPRTAt991qhqSMx7adrbEQ@mail.gmail.com> <f3ac3c95-4935-6662-27ad-a025093b5af3@gmail.com> <CAD3a31XmfCqz-p7Ssky53U7m4fkL0RHGZyM=RVfD5+K-RZ69Gw@mail.gmail.com> <1C9CA252-1689-4F69-BC66-CDCDFE46FE87@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