ALTER TABLE asn_prefix_cache ADD COLUMN prefixes_json JSONB NOT NULL DEFAULT '[]';

UPDATE asn_prefix_cache apc
SET prefixes_json = COALESCE((
    SELECT jsonb_agg(apcr.prefix::text ORDER BY apcr.prefix::text)
    FROM asn_prefix_cache_row apcr
    WHERE apcr.asn = apc.asn
), '[]'::jsonb);

DROP TABLE IF EXISTS asn_prefix_cache_row;
