Simple SELECT query over denormalize data

226 Views Asked by At

The movie lens data have denormalized genres:

movie1  ACTION|ADVENTURE
movie2  ACTION|ADVENTURE|DRAMA
...

Is it possible to write a simple SQL to get the normalized movie-genres:

movie1  ACTION
movie1  ADVENTURE
movie2  ACTION
...

Suppose I'm doing this in MySQL or PostgreSQL.

1

There are 1 best solutions below

2
On BEST ANSWER

For PostgreSQL, you can use unnest with string_to_array:

select name, unnest(string_to_array(genres, '|'))
from movies;