My goal is to take the ad_name strings and (1) split sting at the '-' deliminator and then replace that substring with the correct term with a space. so "peelpads" turns into "peel pads", "gtox" turns into "g tox", "meljeans" turns into "mel jeans", and "alexisskirt" turns into "alexis skirt."
CREATE TABLE facebook_campaigns
(campaign varchar(255),
ad_name varchar(255),
Media_spend numeric(38,6),
day date);
INSERT INTO facebook_campaigns VALUES
('Peel Pads','retargeting-peelpads-201907', 1000),
('Peel Pads','prospecting-peelpads-201907', 3000),
('Peel Pads','prospecting-peelpads-201906', 2000),
('G Tox','prospecting-gtox-201907', 1000),
('G Tox','retargeting-gtox-201907', 1000),
('Pre Fall','prospecting-meljeans-201907', 1000),
('Pre Fall','retargeting-meljeans-201907', 500),
('Pre Fall','retargeting-alexisskirt-201907', 1500),
('Pre Fall','prospecting-alexisskirt-201907', 2000);
I'm able to separate the column by the deliminator but I'm unsure how to isolate that and add the space in the term. This is what I have done so far.
SELECT
ad_name,
regexp_replace('retargeting-peelpads-201907',
'peelpads', 'peel pads'),
SPLIT_PART(ad_name, '-', 2) as product
FROM facebook_campaigns
and my result is
retargeting-peelpads-201907 | retargeting-peel pads-201907 | peelpads
prospecting-peelpads-201907 | retargeting-peel pads-201907| peelpads
I really just want a column that results to
peel pads
I just want a column that says "peel pads" because in the end my goal is to combine that column with the "product_name" column in the table below.
CREATE TABLE order_line_items
(order_line_item_id bigint,
order_id bigint,
product_name varchar(255),
business_unit varchar(255),
source varchar(255));
INSERT INTO order_line_items VALUES
(1, 1,'peel pads','Bananadrinks','facebook'),
(2, 2,'peel pads','Bananadrinks','organic'),
(3, 2,'mel jeans','Redsticks','organic'),
(4, 2,'g tox','Bananadrinks','facebook'),
(5, 3,'alexis skirt','Redsticks','email'),
(6, 4,'alexis skirt','Redsticks','facebook'),
(7, 5,'g tox','Bananadrinks','facebook'),
(8, 5,'mel jeans','Redsticks','facebook'),
(9, 6,'mel jeans','Redsticks','email');
Text to DDL