0

I have a table fluxo, and fluxo have many fluxo_acao, but a entry in fluxo_acao can have three types, and each type have they particularities. to acomplish this, i created more three tables(fluxo_acao_mensagem, fluxo_acao_pergunta and fluxo_acao_escolher_fila), connected to fluxo_acao.

The problem is i can't select any of the three tables, from fluxo, because first i need to check wich type is and them i do the query.

I need a better approat in how to acomplish this relation. Even why i need create another two more. and this is the perfect time to change.

fluxo fluxo_acao other three tables

André Walker
  • 587
  • 7
  • 24
  • Please don't put things in your post other than what's needed to ask it. You could leave a comment that you cross-posted before realizing it was disallowed. Closing means answers are blocked, but you can still get votes. Please edit your posts to improve whenever you can. I think that askers can self-close immediately as a duplicate. PS Your final question is 2 questions with an OR; consider asking 1 good version of 1 of them. I voted the design issue as a duplicate. But if you research being stuck querying, it's also a faq & if you do ask, give a [mre]. [ask] [help] [meta] [meta.se] – philipxy Jan 27 '21 at 19:11
  • My comments are neutral, relevant & helpful. – philipxy Jan 27 '21 at 19:14
  • thanks for your feedback. wasn't the general content, but the way you said. I edited in the top of the question because i was trying to avoid someone to post any answer and a comment may will missed. i'm accepting the duplecate suggestion. I'm done with this subject. – André Walker Jan 27 '21 at 19:29

2 Answers2

0

It's hard to understand what exactly these types are supposed to do, but it sounds like inheritance could help you: https://www.postgresql.org/docs/13/tutorial-inheritance.html

hbrgnr
  • 371
  • 1
  • 11
0

You could add the columns for all three types to fluxo_acao and use a check constraint to ascertain that the correct columns are NULL or NOT NULL for each type. Then the join would be trivial.

For convenience, you could define views on fluxo_acao for each type that show only the pertinent columns.

Laurenz Albe
  • 167,868
  • 16
  • 137
  • 184