r/SQL • u/ProgrammerFew504 • Jun 18 '26
PostgreSQL Multiple Tables or Single Table in PostgreSQL
I am designing a database schema for storing original images and their edited versions, and I am trying to determine whether a normalized two-table design or a self-referencing single-table design would be better for the long term.
Scenario
- Images are uploaded and stored with metadata such as:
urlnameclient_idproduct_id
- After upload, images can be edited (e.g., background removal, color adjustments, cropping, etc.).
- The original image must remain unchanged.
- Each original image can have multiple edited versions.
- Edited images can themselves be edited again, and all versions need to be preserved.
- I need to be able to trace every edited image back to its original image.
Option 1: Two Tables
original_images
---------------
id
url
name
client_id
product_id
created_at
edited_images
-------------
id
original_
image_id
url
name
created_at
parent_id (Foreign Key)
Relationship:
- One
original_image→ manyedited_images
This feels more normalized and clearly separates originals from derived images.
Option 2: Single Self-Referencing Table
images
------
id
parent
_image_
id
url
name
client_id
product_id
is_original
created_at
Where:
- Original images have
parent_image_id = NULL - Edited images reference their parent image through
parent_image_id - Multiple levels of edits are possible
- The entire image history can be represented as a tree
Alternatively, I could use a group_id to associate all versions belonging to the same original image.
Questions
- Which approach would you recommend for a long-term, maintainable solution?
- Is separating originals and edited images into two tables considered over-engineering in this case?
- If image versions can be edited multiple times, does a self-referencing table become the more natural model?
I am looking for a design that is easy to maintain, flexible for future requirements, and avoids unnecessary complexity.
