I have a dataset that looks as follows and I am using Redshift SQL:
CREATE TABLE mytable
(
userid INTEGER NOT NULL PRIMARY KEY,
username VARCHAR(17) NOT NULL,
display_name VARCHAR(13) NOT NULL,
bio VARCHAR(51) NOT NULL,
places VARCHAR(24),
email VARCHAR(25) NOT NULL
);
INSERT INTO mytable (userid, username, display_name, bio, places, email)
VALUES (123, 'cliff.park', 'Cliff Park', 'Student living in Chicago. Born in Phoenix', '[''Chicago'', ''Phoenix'']', '[email protected]');
INSERT INTO mytable (userid, username, display_name, bio, places, email)
VALUES (456, 'sam2234', 'Sam Wright', 'Current Location: Cleveland. Next Location: Orlando', '[''Cleveland'', ''Orlando'']', '[email protected]');
INSERT INTO mytable (userid, username, display_name, bio, places, email)
VALUES (789, 'buckeyes33', 'BuckeyeFan', 'From Columbus… Go Bucks!', '[''Columbus'']', '[email protected]');
INSERT INTO mytable (userid, username, display_name, bio, places, email)
VALUES (1011, 'sarah.patrick4354', 'Sarah Patrick', 'Checkout my clothing line!!!!', '[]', '[email protected]');
What I'm trying to do: Whenever the places field contains multiple selections (for example: ['Chicago', 'Phoenix']) it will create a new row with all of the same fields and data, except for places, which will now only have one option. So the final output should look something like this:
Additionally, it would get rid of the [] and quote string characters so that ['Columbus'] would just be Columbus and any value that is just [] would just be blank/null/empty
