While executing the query to find median I stumble upon this error message- BIGINT UNSIGNED value is out of range in '(median.row_asc - median.row_desc)'
The query that I wrote:
with median as
(select lat_n, row_number () over (order by lat_n asc) as row_asc,row_number () over (order by lat_n desc) as row_desc
from station
)
select round(avg(lat_n),4)
from median
where abs(row_asc-row_desc) <= 1
While doing the same kind in postgresql by creating the table
create table station (id serial primary key,
city varchar(50),
state varchar(50),
lat_n float,
long_w float)
insert into station values
(2,'ctc','odisha',31.546,33.213),
(3,'khorda','odisha',30.546,39.213),
(4,'puri','odisha',41.546,37.213);
with median as
(select lat_n,row_number() over (order by lat_n) as row_asc,
row_number() over(order by lat_n desc) as row_desc from station
)
select round(avg(lat_n),4)
from median
where abs(row_asc-row_desc) <=1
the error:
ERROR: function round(double precision, integer) does not exist
LINE 7: select round(avg(lat_n),4)
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
