Re: Onfly, function generated ID for Select Query

From: Durumdara <durumdara(at)gmail(dot)com>
To: Gustavsson Mikael <mikael(dot)gustavsson(at)smhi(dot)se>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Onfly, function generated ID for Select Query
Date: 2023-03-10 07:41:06
Message-ID: CAEcMXhnWw4aewhMBkZkCJ6S=NDyjGTV=PwfzD+M0d6ZWZtoOqg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Dear Mikael!

Wooooow... that is it!
Thank you!

SELECT product_id, product_name, group_id, ROW_NUMBER () OVER (ORDER BY
product_id) FROM products;

Does this mean that I have to duplicate the order by clause?

SELECT product_id, product_name, group_id, ROW_NUMBER ()
OVER (*ORDER BY product_id, product_name, group_id*)
FROM products
*ORDER BY product_id, product_name, group_id*

To get the same sequence in the ROW_ID-s, and the Query rows?

BR
dd

Gustavsson Mikael <mikael(dot)gustavsson(at)smhi(dot)se> ezt írta (időpont: 2023.
márc. 10., P, 8:33):

> Hi,
>
>
> Is it something like row_number() you want?
> https://www.postgresql.org/docs/current/functions-window.html
>
> KR
> Mikael
> ------------------------------
> *Från:* Durumdara <durumdara(at)gmail(dot)com>
> *Skickat:* den 10 mars 2023 8:12
> *Till:* Postgres General
> *Ämne:* Onfly, function generated ID for Select Query
>
> Dear Members!
>
> I'm searching for a simple solution, like this:
>
> select GetIDForThisSelect(1, 1) as UID, * from anytablehasdoublestringkey
> join othertablehasnotuniqueintegerkey ...
> where ....
>
> Ok, I can make a sequence, but I don't want to use persistent data.
> It is enough to get 1...N as UID for this select.
>
> Like generate_series, but that is generating rows.
>
> Maybe you have some trick to do this.
>
> Thank you for any assistance!
>
> Best regards
> dd
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gustavsson Mikael 2023-03-10 07:48:14 SV: Onfly, function generated ID for Select Query
Previous Message Durumdara 2023-03-10 07:34:53 Get more columns from a lookup type subselect