0

I have a database structure like so (in Postgres):

enter image description here

An entity has a list of actions associated with it. Each Action has one associated row out of all action-specific tables. Each of these action types are separated into different tables because they store significantly different data. All common data is stored on the Action table, but the data specific to the type of action is in the table for that action type.

Ideally, what I am looking to do is create a query that would return the actions for an entity like so. Do you know of a way to query these to produce a result like this?

[
    ...
    {
        action: {
            heat: 450
        }
    }
]

The best I've gotten so far was this...

[
    {
        json: [{ action: {...} }]
    }
]

with a combination of json_agg and json_build_object. Of course, I'm open to alternatives. My SQL skillset is a bit green, so there's a good chance that there's a better way of structuring or querying this.

Thanks!

2
  • Welcome to the DBA.SE community. You aren't really stating what your actual problem is. There is no question in your question. Could you be a bit more specific on what you are trying to achieve and what you are expecting from the community? Thanks.
    – John K. N.
    Commented Sep 7, 2023 at 6:02
  • @JohnK.N. Haha, fair point. Thanks for the feedback. I edited it a bit to clarify what exactly I was asking for, although I have come to the conclusion that there is a much simpler alternative to what I was trying to do here.
    – Gmanicus
    Commented Sep 8, 2023 at 1:38

1 Answer 1

0

I should just use a JSON column on the Action table to store the action-specific data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.