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 1kJN0s-0001Do-1i for pgsql-general@arkaria.postgresql.org; Fri, 18 Sep 2020 20:29: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 1kJN0q-0007KF-JY for pgsql-general@arkaria.postgresql.org; Fri, 18 Sep 2020 20:29:44 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kJMxf-0001Oy-Pf for pgsql-general@lists.postgresql.org; Fri, 18 Sep 2020 20:26:28 +0000 Received: from mail-ot1-x32f.google.com ([2607:f8b0:4864:20::32f]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kJMxd-0000yM-8q for pgsql-general@lists.postgresql.org; Fri, 18 Sep 2020 20:26:26 +0000 Received: by mail-ot1-x32f.google.com with SMTP id q21so6551341ota.8 for ; Fri, 18 Sep 2020 13:26:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=giFU9pE0EnLCUyuScjCIQ+GP+SzZZpRyU9fhKFRTgaY=; b=eZY65873waH13uyevyq6M7BqSTqr5ICExAg6+X2KnaqUdKlQITdUbj6smIHg7A06t+ EV8rotqOXHaYaLAC9q51L1EUVUHgXLFS7EZoYIoHguLt1tz1RLCN/byHgx3GpiazkAT2 xR7PdjiGZjNx6ag2PNCR9aSzr4MFH69/I1p+HZJ5/9yW7qzhGga/7LCwomPkIOLvEM2q yO+MAMoYbr+E3CW5kP0TfoGWNtnVYtGxOhxItKoFhuIbvRaKHJ7GEEXzcckLKDVWMxyZ JHsNUx5+b+CUQNFeveDuaRJ4UCEmgEVLXsTDEpC1PO1la9IzJLon6k1LaiZK/n7kQ2fy eA6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=giFU9pE0EnLCUyuScjCIQ+GP+SzZZpRyU9fhKFRTgaY=; b=k00ompuqsOrpujuFxyTCQpeggd/rkFe9KtAaaPzo910/q7hMMBUyO15IfGBL+2Ntpq I4PD+6EKYlzGyrjpbus0BGXBSb8NJcaSgiw821+I/zlC7ONd8WFRA3ZTmY//2ddgeu3o X32cINbj8EsNDah0gQ9tyn1r9J0ttVH8ZUnCu5iL23JMmfPrg8bPPA6MYwXZBblnkYcK dhtOuxIR0eWPpJaQki1RoAFScpLNNx6kYeZ4COmaC7OfjYzRCexFP+6MslubX6vS7OBw pzjbM0AIJE0AIR9azCl/NM1d1Ck7lD5Hkc/3MeZw7grLymVgKDMBReSwEEGZ5hmdBthH BkSQ== X-Gm-Message-State: AOAM530+XAXA7Kr9PVaKsS2CWRAEoJXKvhsb74K537GciWu/9WAY+UQI 05LJDWygYzmFO1eP+BEotmONO4HwaflrBw== X-Google-Smtp-Source: ABdhPJxtHzlUDtQH0qTaV8OgS7F0LqOeBwEMIPvNmHxkMOokedy2HrQWNI6tTGlO3n0g02li9wI3oA== X-Received: by 2002:a9d:787:: with SMTP id 7mr23560895oto.202.1600460784360; Fri, 18 Sep 2020 13:26:24 -0700 (PDT) Received: from [192.168.1.10] (ip174-67-143-111.no.no.cox.net. [174.67.143.111]) by smtp.googlemail.com with ESMTPSA id 126sm4135736oof.28.2020.09.18.13.26.23 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 18 Sep 2020 13:26:23 -0700 (PDT) Subject: Re: How to write such a query To: "pgsql-generallists.postgresql.org" References: <912dd33c-c837-a226-111f-413fcb7321c1@aklaver.com> From: Ron Message-ID: <0cc50818-11e0-7e42-2134-41cfc88197a2@gmail.com> Date: Fri, 18 Sep 2020 15:26:23 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------016A5906C0D4F02BAB54AA66" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------016A5906C0D4F02BAB54AA66 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 9/18/20 3:18 PM, Igor Korot wrote: > Hi, Ken, > > On Fri, Sep 18, 2020 at 2:46 PM Ken Tanzer > 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 = ; > > > 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. > > > Thank you for the info. > My problem is that I want to emulate Access behavior. > > As I said - Access does it without changing the query internally (I presume). > > I want to do the same with PostgreSQL. > > I'm just trying to understand how to make it work for any query > > I can have 3,4,5 tables, query them and then update the Nth record in the > resulting recordset. > > Access does it, PowerBuilder does it. > > I just want to understand how. They do it by hiding the details from you. -- Angular momentum makes the world go 'round. --------------016A5906C0D4F02BAB54AA66 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit On 9/18/20 3:18 PM, Igor Korot wrote:
Hi, Ken,

On Fri, Sep 18, 2020 at 2:46 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.

Thank you for the info.
My problem is that I want to emulate Access behavior.

As I said - Access does it without changing the query internally (I presume).

I want to do the same with PostgreSQL.

I'm just trying to understand how to make it work for any query

I can have 3,4,5 tables, query them and then update the Nth record in the resulting recordset.

Access does it, PowerBuilder does it.

I just want to understand how.

They do it by hiding the details from you.

--
Angular momentum makes the world go 'round.
--------------016A5906C0D4F02BAB54AA66--