Show enum types in postgress

select enum_range(null::my_type)
16 сентября 2020, 18:20

Update multiple rows with one query in postgresql

CREATE TABLE table1 ( 
	"id" Integer NOT NULL,
	"a" Text NOT NULL,
	"b" Text NOT NULL );
insert into table1 values  
(1, 'a', 'b'),
(2, 'a', 'b')
update table1 as t set 
  a = data.a,
  b = data.b
from (values
  (1, 'a1', 'b1'),
  (2, 'a2', 'b2')
) as data(id, a, b)
where t.id = data.id
29 августа 2020, 21:41

Difference between ROW_NUBER(), RANK(), DENSE_RANK() in postgresql

WITH T(StyleID, ID)
     AS (SELECT 1,1 UNION ALL
         SELECT 1,1 UNION ALL
         SELECT 1,1 UNION ALL
         SELECT 1,2)
SELECT *,
       RANK() OVER(PARTITION BY StyleID ORDER BY ID)       AS 'RANK',
       ROW_NUMBER() OVER(PARTITION BY StyleID ORDER BY ID) AS 'ROW_NUMBER',
       DENSE_RANK() OVER(PARTITION BY StyleID ORDER BY ID) AS 'DENSE_RANK'
FROM   T  
Returns

StyleID     ID       RANK      ROW_NUMBER      DENSE_RANK
----------- -------- --------- --------------- ----------
1           1        1         1               1
1           1        1         2               1
1           1        1         3               1
1           2        4         4               2
6 августа 2020, 20:48