CREATE TABLE products (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
tags TEXT[] NOT NULL, -- Array of tags
price NUMERIC(10, 2),
details JSONB -- Store nested JSON data
);
Example: Normalizing Nested Data
If you want to avoid JSON and normalize the data:
sql
CREATE TABLE products (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
price NUMERIC(10, 2)
);
CREATE TABLE product_tags (
product_id INT REFERENCES products(id),
tag TEXT NOT NULL,
PRIMARY KEY (product_id, tag)
);
CREATE TABLE product_details (
product_id INT REFERENCES products(id),
weight TEXT,
height TEXT,
width TEXT
);
Next Steps:
Share your data structure (e.g., JSON, CSV, or schema).
Describe relationships between entities.
Mention any constraints (e.g., unique keys, foreign keys).
Let me know, and I’ll generate the exact SQL schema for you! 🚀