Split string row to multiple columns - PostgreSQL The 2019 Stack Overflow Developer Survey Results Are InAdd a column with a default value to an existing table in SQL ServerPostgreSQL “DESCRIBE TABLE”How to concatenate text from multiple rows into a single text string in SQL server?How do I iterate over the words of a string?How do you split a list into evenly sized chunks?Inserting multiple rows in a single SQL query?Show tables in PostgreSQLHow do I split a string on a delimiter in Bash?Using group by on multiple columnsHow to exit from PostgreSQL command line utility: psql
Why don't hard Brexiteers insist on a hard border to prevent illegal immigration after Brexit?
How to translate "being like"?
Button changing its text & action. Good or terrible?
How can I define good in a religion that claims no moral authority?
Why isn't the circumferential light around the M87 black hole's event horizon symmetric?
Relationship between Gromov-Witten and Taubes' Gromov invariant
Falsification in Math vs Science
If a sorcerer casts the Banishment spell on a PC while in Avernus, does the PC return to their home plane?
Geography at the pixel level
Flight paths in orbit around Ceres?
If I score a critical hit on an 18 or higher, what are my chances of getting a critical hit if I roll 3d20?
A word that means fill it to the required quantity
Can withdrawing asylum be illegal?
Cooking pasta in a water boiler
How to display lines in a file like ls displays files in a directory?
Can a flute soloist sit?
What's the name of these plastic connectors
What is the most efficient way to store a numeric range?
Is it ok to offer lower paid work as a trial period before negotiating for a full-time job?
How do you keep chess fun when your opponent constantly beats you?
Are spiders unable to hurt humans, especially very small spiders?
Output the Arecibo Message
How to notate time signature switching consistently every measure
Does adding complexity mean a more secure cipher?
Split string row to multiple columns - PostgreSQL
The 2019 Stack Overflow Developer Survey Results Are InAdd a column with a default value to an existing table in SQL ServerPostgreSQL “DESCRIBE TABLE”How to concatenate text from multiple rows into a single text string in SQL server?How do I iterate over the words of a string?How do you split a list into evenly sized chunks?Inserting multiple rows in a single SQL query?Show tables in PostgreSQLHow do I split a string on a delimiter in Bash?Using group by on multiple columnsHow to exit from PostgreSQL command line utility: psql
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
How can i split one column/row to multiple columns and same row. The idea is this:
I have a query that looks this:
SELECT
i.account_id AS account_id,
c.url_tags AS url_tags,
CAST(to_char(date_start, 'YYYYMM') AS INT) AS month_id,
sum(clicks) AS clicks,
sum(impressions) AS impressions,
sum(reach) AS reach,
sum(spend) AS spend,
sum(total_actions) AS total_actions
FROM schema.ads_insights AS i
INNER JOIN schema.ads as a ON a.id=i.ad_id
INNER JOIN schema.adcreative as c ON c.id=a.creative__id
WHERE
EXTRACT(YEAR FROM date_start) = '2018'
GROUP BY i.account_id, month_id, c.url_tags
This outputs this:(removed some columns)
|----||--------------------------------------------------------------||----|
| ID || url || mo |
|----||--------------------------------------------------------------||----|
| 1 || utm_source=source&utm_medium=medium&utm_term=term || 12 |
|----||--------------------------------------------------------------||----|
|----||--------------------------------------------------------------||----|
| 2 || utm_source=source2&utm_medium=medium2&utm_term=term2 || 43 |
|----||--------------------------------------------------------------||----|
What i would want without any Backend logic. We have a connector from our database to a visualization platform(Google Data Studio) that feeds the data without any form for manipulating option. This is why i want to manipulate the query so it is compatible without any Backend-code.
This is what i want in result of this query:
|----||------------||------------||----------||--------|
| ID || utm_source || utm_medium || utm_term || mo |
|----||------------||------------||----------||--------|
| 1 || source || medium || term || 12 |
|----||------------||------------||----------||--------|
| 2 || source2 || medium2 || term2 || 43 |
|----||------------||------------||----------||--------|
Would this be possible?
sql postgresql split
add a comment |
How can i split one column/row to multiple columns and same row. The idea is this:
I have a query that looks this:
SELECT
i.account_id AS account_id,
c.url_tags AS url_tags,
CAST(to_char(date_start, 'YYYYMM') AS INT) AS month_id,
sum(clicks) AS clicks,
sum(impressions) AS impressions,
sum(reach) AS reach,
sum(spend) AS spend,
sum(total_actions) AS total_actions
FROM schema.ads_insights AS i
INNER JOIN schema.ads as a ON a.id=i.ad_id
INNER JOIN schema.adcreative as c ON c.id=a.creative__id
WHERE
EXTRACT(YEAR FROM date_start) = '2018'
GROUP BY i.account_id, month_id, c.url_tags
This outputs this:(removed some columns)
|----||--------------------------------------------------------------||----|
| ID || url || mo |
|----||--------------------------------------------------------------||----|
| 1 || utm_source=source&utm_medium=medium&utm_term=term || 12 |
|----||--------------------------------------------------------------||----|
|----||--------------------------------------------------------------||----|
| 2 || utm_source=source2&utm_medium=medium2&utm_term=term2 || 43 |
|----||--------------------------------------------------------------||----|
What i would want without any Backend logic. We have a connector from our database to a visualization platform(Google Data Studio) that feeds the data without any form for manipulating option. This is why i want to manipulate the query so it is compatible without any Backend-code.
This is what i want in result of this query:
|----||------------||------------||----------||--------|
| ID || utm_source || utm_medium || utm_term || mo |
|----||------------||------------||----------||--------|
| 1 || source || medium || term || 12 |
|----||------------||------------||----------||--------|
| 2 || source2 || medium2 || term2 || 43 |
|----||------------||------------||----------||--------|
Would this be possible?
sql postgresql split
add a comment |
How can i split one column/row to multiple columns and same row. The idea is this:
I have a query that looks this:
SELECT
i.account_id AS account_id,
c.url_tags AS url_tags,
CAST(to_char(date_start, 'YYYYMM') AS INT) AS month_id,
sum(clicks) AS clicks,
sum(impressions) AS impressions,
sum(reach) AS reach,
sum(spend) AS spend,
sum(total_actions) AS total_actions
FROM schema.ads_insights AS i
INNER JOIN schema.ads as a ON a.id=i.ad_id
INNER JOIN schema.adcreative as c ON c.id=a.creative__id
WHERE
EXTRACT(YEAR FROM date_start) = '2018'
GROUP BY i.account_id, month_id, c.url_tags
This outputs this:(removed some columns)
|----||--------------------------------------------------------------||----|
| ID || url || mo |
|----||--------------------------------------------------------------||----|
| 1 || utm_source=source&utm_medium=medium&utm_term=term || 12 |
|----||--------------------------------------------------------------||----|
|----||--------------------------------------------------------------||----|
| 2 || utm_source=source2&utm_medium=medium2&utm_term=term2 || 43 |
|----||--------------------------------------------------------------||----|
What i would want without any Backend logic. We have a connector from our database to a visualization platform(Google Data Studio) that feeds the data without any form for manipulating option. This is why i want to manipulate the query so it is compatible without any Backend-code.
This is what i want in result of this query:
|----||------------||------------||----------||--------|
| ID || utm_source || utm_medium || utm_term || mo |
|----||------------||------------||----------||--------|
| 1 || source || medium || term || 12 |
|----||------------||------------||----------||--------|
| 2 || source2 || medium2 || term2 || 43 |
|----||------------||------------||----------||--------|
Would this be possible?
sql postgresql split
How can i split one column/row to multiple columns and same row. The idea is this:
I have a query that looks this:
SELECT
i.account_id AS account_id,
c.url_tags AS url_tags,
CAST(to_char(date_start, 'YYYYMM') AS INT) AS month_id,
sum(clicks) AS clicks,
sum(impressions) AS impressions,
sum(reach) AS reach,
sum(spend) AS spend,
sum(total_actions) AS total_actions
FROM schema.ads_insights AS i
INNER JOIN schema.ads as a ON a.id=i.ad_id
INNER JOIN schema.adcreative as c ON c.id=a.creative__id
WHERE
EXTRACT(YEAR FROM date_start) = '2018'
GROUP BY i.account_id, month_id, c.url_tags
This outputs this:(removed some columns)
|----||--------------------------------------------------------------||----|
| ID || url || mo |
|----||--------------------------------------------------------------||----|
| 1 || utm_source=source&utm_medium=medium&utm_term=term || 12 |
|----||--------------------------------------------------------------||----|
|----||--------------------------------------------------------------||----|
| 2 || utm_source=source2&utm_medium=medium2&utm_term=term2 || 43 |
|----||--------------------------------------------------------------||----|
What i would want without any Backend logic. We have a connector from our database to a visualization platform(Google Data Studio) that feeds the data without any form for manipulating option. This is why i want to manipulate the query so it is compatible without any Backend-code.
This is what i want in result of this query:
|----||------------||------------||----------||--------|
| ID || utm_source || utm_medium || utm_term || mo |
|----||------------||------------||----------||--------|
| 1 || source || medium || term || 12 |
|----||------------||------------||----------||--------|
| 2 || source2 || medium2 || term2 || 43 |
|----||------------||------------||----------||--------|
Would this be possible?
sql postgresql split
sql postgresql split
edited Mar 8 at 10:58
a_horse_with_no_name
308k46471572
308k46471572
asked Mar 8 at 10:56
Ali DurraniAli Durrani
407
407
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
use SUBSTRING
select substring(s from 'utm_source=(.*?)(&|$)') as utm_source,
substring(s from 'utm_medium=(.*?)(&|$)') as utm_medium,
substring(s from 'utm_term=(.*?)(&|$)') as utm_term
from t;
Demo
Thanks @Kaushik Nayak, worked perfekt!
– Ali Durrani
Mar 11 at 7:55
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55061743%2fsplit-string-row-to-multiple-columns-postgresql%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
use SUBSTRING
select substring(s from 'utm_source=(.*?)(&|$)') as utm_source,
substring(s from 'utm_medium=(.*?)(&|$)') as utm_medium,
substring(s from 'utm_term=(.*?)(&|$)') as utm_term
from t;
Demo
Thanks @Kaushik Nayak, worked perfekt!
– Ali Durrani
Mar 11 at 7:55
add a comment |
use SUBSTRING
select substring(s from 'utm_source=(.*?)(&|$)') as utm_source,
substring(s from 'utm_medium=(.*?)(&|$)') as utm_medium,
substring(s from 'utm_term=(.*?)(&|$)') as utm_term
from t;
Demo
Thanks @Kaushik Nayak, worked perfekt!
– Ali Durrani
Mar 11 at 7:55
add a comment |
use SUBSTRING
select substring(s from 'utm_source=(.*?)(&|$)') as utm_source,
substring(s from 'utm_medium=(.*?)(&|$)') as utm_medium,
substring(s from 'utm_term=(.*?)(&|$)') as utm_term
from t;
Demo
use SUBSTRING
select substring(s from 'utm_source=(.*?)(&|$)') as utm_source,
substring(s from 'utm_medium=(.*?)(&|$)') as utm_medium,
substring(s from 'utm_term=(.*?)(&|$)') as utm_term
from t;
Demo
answered Mar 8 at 11:08
Kaushik NayakKaushik Nayak
21.8k41332
21.8k41332
Thanks @Kaushik Nayak, worked perfekt!
– Ali Durrani
Mar 11 at 7:55
add a comment |
Thanks @Kaushik Nayak, worked perfekt!
– Ali Durrani
Mar 11 at 7:55
Thanks @Kaushik Nayak, worked perfekt!
– Ali Durrani
Mar 11 at 7:55
Thanks @Kaushik Nayak, worked perfekt!
– Ali Durrani
Mar 11 at 7:55
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55061743%2fsplit-string-row-to-multiple-columns-postgresql%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown