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;








0















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?










share|improve this question






























    0















    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?










    share|improve this question


























      0












      0








      0








      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?










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 8 at 10:58









      a_horse_with_no_name

      308k46471572




      308k46471572










      asked Mar 8 at 10:56









      Ali DurraniAli Durrani

      407




      407






















          1 Answer
          1






          active

          oldest

          votes


















          3














          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






          share|improve this answer























          • Thanks @Kaushik Nayak, worked perfekt!

            – Ali Durrani
            Mar 11 at 7:55











          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
          );



          );













          draft saved

          draft discarded


















          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









          3














          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






          share|improve this answer























          • Thanks @Kaushik Nayak, worked perfekt!

            – Ali Durrani
            Mar 11 at 7:55















          3














          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






          share|improve this answer























          • Thanks @Kaushik Nayak, worked perfekt!

            – Ali Durrani
            Mar 11 at 7:55













          3












          3








          3







          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






          share|improve this answer













          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







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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

















          • 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



















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

          Алба-Юлія

          Захаров Федір Захарович