sqlpostgresql

How to filter results in SQL tables when number of columns is not the same in different tables?


We worked to create a table in SQL and we need to create a function which filters results based on the event.

However festivals contains only 5 columns and concert contains 6 columns.

This throws an error when we need to filter and obtain only the columns relevant to the event queried.

I have tried to unify the column in addition by using an alias, but this doesnt help to generalize a filter function which filters in any case, despite the number of columns.

Here you can find more in detail: https://pastebin.com/bQR9DeH1


Solution

  • The issue probably is not because of the difference in columns but because of the custom types that you have added in for the columns sala and castEvento.

    I tried running with varying columns, it seems to run fine but I have replaced the data type of sala and castEvento with valid data types(eg text).

    Fiddle

    You either need to define custom data types for those columns or use valid data types.