In PostgreSQL v15.6 using TimescaleDB v2.14.2 I am trying to understand the “max_n” function from documentation:
CREATE TABLE stock_sales(
ts TIMESTAMPTZ,
symbol TEXT,
price FLOAT,
volume INT
);
insert into stock_sales values (current_timestamp, 'AAA', 10, 100),(current_timestamp, 'AAA', 20, 110),(current_timestamp, 'AAA', 30, 120);
SELECT
(data).time,
(data).symbol,
value AS transaction
FROM
into_values((
SELECT max_n_by(price * volume, stock_sales, 10)
FROM stock_sales
),
NULL::stock_sales);
And above select from documentation is failing with error:
ERROR: function max_n_by(double precision, stock_sales, integer) does not exist
LINE 7: SELECT max_n_by(price * volume, stock_sales, 10)
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.