Sphere
Log in Join
☆ 15

JSONB column or a separate table?

Product attributes vary by category. A JSONB column is convenient, but I need to filter by a few attributes. Should I normalise those into columns?

⚑ Report

3 replies

☆ 0
N Nate ·2026-11-01#1

Keep JSONB for the long tail and promote only the attributes you filter on into real columns or a generated column with a B-tree index.

⚑ Report
☆ 0
S Sofia ·2026-11-01#2

Can I index keys inside JSONB directly?

⚑ Report
☆ 0
R Robin ·2026-11-01#3

Yes, with a GIN index for containment queries. For equality on one key, an expression index on (data->>'color') is usually faster.

⚑ Report
Log in to reply.