add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
Help with an interesting Postgres question: Why isn't an Index Only Scan used on a partition accessed via the parent table?.
create type ratio as (numerator bigint, denominator bigint);

create table my_ratios(id bigint, val ratio);

-- this works
-- insert into my_ratios (id, val) values (1, (22, 7)) returning *;

-- this does not work:
-- insert into my_ratios
-- SELECT
-- round(n::float / d * 100)
-- , (n, d) as ratio -- cannot cast type record to ratio
-- FROM generate_series(21, 23) n
-- , generate_series(6, 8) d
-- returning *;

-- this works tho:
insert into my_ratios
SELECT
round(n::float / d * 100)
, cast(cast((n, d) as text) as ratio)
FROM generate_series(21, 23) n
, generate_series(6, 8) d
returning *;


id val
350 (21,6)
300 (21,7)
262 (21,8)
367 (22,6)
314 (22,7)
275 (22,8)
383 (23,6)
329 (23,7)
288 (23,8)