Re: How to write such a query

Поиск
Список
Период
Сортировка
От Igor Korot
Тема Re: How to write such a query
Дата
Msg-id CA+FnnTwRr2VbwQSd71jnAtNrgAMqO57AmTO-OqeA6Te-mjMORQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: How to write such a query  (Ken Tanzer <ken.tanzer@gmail.com>)
Ответы Re: How to write such a query  (Thomas Kellerer <shammat@gmx.net>)
Re: How to write such a query  (Ron <ronljohnsonjr@gmail.com>)
Re: How to write such a query  ("David G. Johnston" <david.g.johnston@gmail.com>)
Re: How to write such a query  (Adrian Klaver <adrian.klaver@aklaver.com>)
Re: How to write such a query  (Francisco Olarte <folarte@peoplecall.com>)
Список pgsql-general
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.

Thank you.


Cheers,
Ken
--
AGENCY Software  
A Free Software data system
By and for non-profits
(253) 245-3801

learn more about AGENCY or
follow the discussion.

В списке pgsql-general по дате отправления:

Предыдущее
От: Rob Sargent
Дата:
Сообщение: Re: How to write such a query
Следующее
От: Thomas Kellerer
Дата:
Сообщение: Re: How to write such a query