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 TABLE namespace_list (id int, namespace_ids json DEFAULT '[]'::json);
INSERT INTO namespace_list VALUES
(1, '[1,2,3]')
, (2, '[5,9,3]');
2 rows affected
TABLE namespace_list;
id | namespace_ids |
---|---|
1 | [1,2,3] |
2 | [5,9,3] |
CREATE OR REPLACE FUNCTION json_arr2int_arr(_js json)
RETURNS int[] LANGUAGE sql IMMUTABLE PARALLEL SAFE AS
'SELECT ARRAY(SELECT json_array_elements_text(_js)::int)';
ALTER TABLE namespace_list
ALTER COLUMN namespace_ids DROP DEFAULT
, ALTER COLUMN namespace_ids TYPE int[] USING json_arr2int_arr(namespace_ids);
TABLE namespace_list;
id | namespace_ids |
---|---|
1 | {1,2,3} |
2 | {5,9,3} |