1

I am using go and pq to interface with my postgres database.

I have a simple user table which has basic fields. Id, name, type. My auxillary table, admin inherits from user and adds it's own field panel, and another one that is owner and adds owner. Whether that be using table inheritance, or a supporting table.

My question is if I hit and endpoint that points to user/1 at this point I don't know what type of user this person is yet here. I know we can use jwts and other ways to provide this from the front end. I'm more curious about if there is a way to figure out the user and it's type and query the additional fields in one query?

Ie. I hit the endpoint I would Select from users, get the type, then use that type to get the additional fields. So I would effectively be doing two queries on two tables to get the complete data. Is there a better solution of doing this? Is there some optimizations I could do.

Byrd
  • 867
  • 3
  • 12
  • 24
  • Could you provide a more clear example of your schema, please? – Schwern May 12 '19 at 05:04
  • You can get the information which type it is with a single query. But it's not possible to include all columns from all descendant tables with that query. To get the other columns, you need to query the other tables. –  May 12 '19 at 05:24

0 Answers0