Re: How to write such a query

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Igor Korot <ikorot01(at)gmail(dot)com>, Ken Tanzer <ken(dot)tanzer(at)gmail(dot)com>
Cc: Ron <ronljohnsonjr(at)gmail(dot)com>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: How to write such a query
Date: 2020-09-19 00:40:27
Message-ID: b4809132-c8e9-a813-5d3e-b73c9184b191@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 9/18/20 1:18 PM, Igor Korot wrote:
> Hi, Ken,
>
> On Fri, Sep 18, 2020 at 2:46 PM Ken Tanzer <ken(dot)tanzer(at)gmail(dot)com
> <mailto:ken(dot)tanzer(at)gmail(dot)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.

You mean you are doing a join over 5 tables and then updating some
record that is the output of the join?

If so are you updating all the values or a value or some portion of the
values?

This is being done in a form or in the query builder?

>
> Access does it, PowerBuilder does it.
>
> I just want to understand how.
>
> Thank you.
>
>
> Cheers,
> Ken
> --
> AGENCY Software
> A Free Software data system
> By and for non-profits
> /http://agency-software.org//
> /https://demo.agency-software.org/client/
> ken(dot)tanzer(at)agency-software(dot)org <mailto:ken(dot)tanzer(at)agency-software(dot)org>
> (253) 245-3801
>
> Subscribe to the mailing list
> <mailto:agency-general-request(at)lists(dot)sourceforge(dot)net?body=subscribe> to
> learn more about AGENCY or
> follow the discussion.
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Francisco Olarte 2020-09-19 07:53:20 Re: How to write such a query
Previous Message Ken Tanzer 2020-09-18 22:18:17 Re: How to write such a query