How to divide one row in various?

38
October 17, 2019, at 09:40 AM

I have a column data in a postgresql table that receive data like this: |A|C|F|L|T|U|

The others columns are name, date

Example:

NAME    | DATE       | DATA
ALYSSON | 2019-01-01 | |A|B|C|

How to create a select that return:

NAME    | DATE       | DATA
ALYSSON | 2019-01-01 | A
ALYSSON | 2019-01-01 | B
ALYSSON | 2019-01-01 | C
Answer 1

You can use string_to_array along with unnest to break your data into first an array and then separate rows.

select * FROM (
  select name, date, unnest(string_to_array(data, '|')) as data from stuff
) AS sub
WHERE sub.data != '';

The WHERE clause is required to remove the empty strings at the beginning and end of your data.

READ ALSO
Making div element dynamic with another function

Making div element dynamic with another function

I have a block of code that I want to try and refactor

28
resize svg wrapped in div that is wrapped in div

resize svg wrapped in div that is wrapped in div

I'm having a problem coverting inline SVG to be wrapped in divsI was using nested SVGs before and now I'm told I have to use nested divs with inline SVG

6
responsive grid of different sized images with real world proportions and scale

responsive grid of different sized images with real world proportions and scale

I have a laravel site that loads product images into a grid-container--fit row through a @foreach loopThe images are all sorts of different sizes, some are portrait and some are landscape

15