Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create row numbers in Redshift?

I would like to create a table using a select statement and add a column with row numbers

So I'd like to write something like:

create table schema.table_w_rownumbers as 
select 
    identity(1, 1) as nrum,
    foo.*
from schema.initial_table as foo;
like image 875
d_a_c321 Avatar asked Dec 19 '22 13:12

d_a_c321


1 Answers

This worked for me!

create table schema.table_w_rownumbers as 
select 
  row_number() over (partition by 1) as nrum,
  foo.*
from schema.initial_table as foo;
like image 62
user 923227 Avatar answered Jan 04 '23 06:01

user 923227



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!