PostgreSQL return and sql tuple descriptions are incompatible The Next CEO of Stack OverflowPostgreSQL “DESCRIBE TABLE”Show tables in PostgreSQLPostgreSQL AutoincrementCreating a copy of a database in PostgreSQLHow can I drop all the tables in a PostgreSQL database?How to drop a PostgreSQL database if there are active connections to it?How to start PostgreSQL server on Mac OS X?How to exit from PostgreSQL command line utility: psqlHow to change PostgreSQL user password?Which version of PostgreSQL am I running?

What can we do to stop prior company from asking us questions?

Between two walls

How does the mv command work with external drives?

What's the best way to handle refactoring a big file?

What was the first Unix version to run on a microcomputer?

Written every which way

If the heap is initialized for security, then why is the stack uninitialized?

Can I equip Skullclamp on a creature I am sacrificing?

How to solve a differential equation with a term to a power?

Is HostGator storing my password in plaintext?

Are there any limitations on attacking while grappling?

Is there a way to save my career from absolute disaster?

Received an invoice from my ex-employer billing me for training; how to handle?

Elegant way to replace substring in a regex with optional groups in Python?

How to start emacs in "nothing" mode (`fundamental-mode`)

Sending manuscript to multiple publishers

Is it my responsibility to learn a new technology in my own time my employer wants to implement?

Rotate a column

What does convergence in distribution "in the Gromov–Hausdorff" sense mean?

Is it professional to write unrelated content in an almost-empty email?

I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin

Indicator light circuit

How to count occurrences of text in a file?

What connection does MS Office have to Netscape Navigator?



PostgreSQL return and sql tuple descriptions are incompatible



The Next CEO of Stack OverflowPostgreSQL “DESCRIBE TABLE”Show tables in PostgreSQLPostgreSQL AutoincrementCreating a copy of a database in PostgreSQLHow can I drop all the tables in a PostgreSQL database?How to drop a PostgreSQL database if there are active connections to it?How to start PostgreSQL server on Mac OS X?How to exit from PostgreSQL command line utility: psqlHow to change PostgreSQL user password?Which version of PostgreSQL am I running?










0















What's wrong with this query? I've been bashing my head with the data type but didn't see any problem.



Thanks.



select * from crosstab(
$$
select * from
(values
(1546300800, 187923, 1.5),
(1546300800, 187924, 200),
(1546300800, 187926, 120),
(1546300800, 187927, 100),
(1546387200, 187923, 1.5),
(1546387200, 187924, 250),
(1546387200, 187926, 120),
(1546387200, 187927, 125),
(1546473600, 187923, 1.5),
(1546473600, 187924, 275),
(1546473600, 187926, 120),
(1546473600, 187927, 137.5),
(1546560000, 187923, 1.75)
) as t (datetime, trace, value)
$$
)
as final_result (
unixdatetime int,
trace1 double precision,
trace2 double precision,
trace3 double precision,
trace4 double precision
)









share|improve this question






















  • You do have the tablefunc module configured? create extension tablefunc;

    – Ancoron
    Mar 21 at 17:11















0















What's wrong with this query? I've been bashing my head with the data type but didn't see any problem.



Thanks.



select * from crosstab(
$$
select * from
(values
(1546300800, 187923, 1.5),
(1546300800, 187924, 200),
(1546300800, 187926, 120),
(1546300800, 187927, 100),
(1546387200, 187923, 1.5),
(1546387200, 187924, 250),
(1546387200, 187926, 120),
(1546387200, 187927, 125),
(1546473600, 187923, 1.5),
(1546473600, 187924, 275),
(1546473600, 187926, 120),
(1546473600, 187927, 137.5),
(1546560000, 187923, 1.75)
) as t (datetime, trace, value)
$$
)
as final_result (
unixdatetime int,
trace1 double precision,
trace2 double precision,
trace3 double precision,
trace4 double precision
)









share|improve this question






















  • You do have the tablefunc module configured? create extension tablefunc;

    – Ancoron
    Mar 21 at 17:11













0












0








0








What's wrong with this query? I've been bashing my head with the data type but didn't see any problem.



Thanks.



select * from crosstab(
$$
select * from
(values
(1546300800, 187923, 1.5),
(1546300800, 187924, 200),
(1546300800, 187926, 120),
(1546300800, 187927, 100),
(1546387200, 187923, 1.5),
(1546387200, 187924, 250),
(1546387200, 187926, 120),
(1546387200, 187927, 125),
(1546473600, 187923, 1.5),
(1546473600, 187924, 275),
(1546473600, 187926, 120),
(1546473600, 187927, 137.5),
(1546560000, 187923, 1.75)
) as t (datetime, trace, value)
$$
)
as final_result (
unixdatetime int,
trace1 double precision,
trace2 double precision,
trace3 double precision,
trace4 double precision
)









share|improve this question














What's wrong with this query? I've been bashing my head with the data type but didn't see any problem.



Thanks.



select * from crosstab(
$$
select * from
(values
(1546300800, 187923, 1.5),
(1546300800, 187924, 200),
(1546300800, 187926, 120),
(1546300800, 187927, 100),
(1546387200, 187923, 1.5),
(1546387200, 187924, 250),
(1546387200, 187926, 120),
(1546387200, 187927, 125),
(1546473600, 187923, 1.5),
(1546473600, 187924, 275),
(1546473600, 187926, 120),
(1546473600, 187927, 137.5),
(1546560000, 187923, 1.75)
) as t (datetime, trace, value)
$$
)
as final_result (
unixdatetime int,
trace1 double precision,
trace2 double precision,
trace3 double precision,
trace4 double precision
)






postgresql crosstab






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 21 at 17:02









Quy Vu XuanQuy Vu Xuan

296




296












  • You do have the tablefunc module configured? create extension tablefunc;

    – Ancoron
    Mar 21 at 17:11

















  • You do have the tablefunc module configured? create extension tablefunc;

    – Ancoron
    Mar 21 at 17:11
















You do have the tablefunc module configured? create extension tablefunc;

– Ancoron
Mar 21 at 17:11





You do have the tablefunc module configured? create extension tablefunc;

– Ancoron
Mar 21 at 17:11












2 Answers
2






active

oldest

votes


















1














Although you didn't mention which error you are getting, this is how to make it work:



Initialize the module tablefunc:



CREATE EXTENSION tablefunc;


Then, you need to be careful about the data types. PostgreSQL can be quite picky and doesn't auto-magically convert them in many cases. In this case, they must match or at least the crosstab column type definitions must be able to completely contain the types as returned by the crosstab function SQL.



You have 2 options here:



  1. Adapt the outer type to a variable numeric type, e.g. decimal:

select * from crosstab(
$$
select * from (values
(1546300800, 187923, 1.5),
(1546300800, 187924, 200),
(1546300800, 187926, 120),
(1546300800, 187927, 100),
(1546387200, 187923, 1.5),
(1546387200, 187924, 250),
(1546387200, 187926, 120),
(1546387200, 187927, 125),
(1546473600, 187923, 1.5),
(1546473600, 187924, 275),
(1546473600, 187926, 120),
(1546473600, 187927, 137.5),
(1546560000, 187923, 1.75)
) as t (datetime, trace, value)
$$
) as final_result (
unixdatetime int,
trace1 decimal,
trace2 decimal,
trace3 decimal,
trace4 decimal
);


  1. Alternatively, make sure the crosstab SQL returns the desired type explicitly, e.g.:

select * from crosstab(
$$
select * from (values
(1546300800, 187923, 1.5::double precision),
(1546300800, 187924, 200::double precision),
(1546300800, 187926, 120::double precision),
(1546300800, 187927, 100::double precision),
(1546387200, 187923, 1.5::double precision),
(1546387200, 187924, 250::double precision),
(1546387200, 187926, 120::double precision),
(1546387200, 187927, 125::double precision),
(1546473600, 187923, 1.5::double precision),
(1546473600, 187924, 275::double precision),
(1546473600, 187926, 120::double precision),
(1546473600, 187927, 137.5::double precision),
(1546560000, 187923, 1.75::double precision)
) as t (datetime, trace, value)
$$
) as final_result (
unixdatetime int,
trace1 double precision,
trace2 double precision,
trace3 double precision,
trace4 double precision
);


The result in both cases looks as follows:



 unixdatetime | trace1 | trace2 | trace3 | trace4 
--------------+--------+--------+--------+--------
1546300800 | 1.5 | 200 | 120 | 100
1546387200 | 1.5 | 250 | 120 | 125
1546473600 | 1.5 | 275 | 120 | 137.5
1546560000 | 1.75 | | |
(4 rows)





share|improve this answer






























    1














    Thank you guys for the help! Ancoron's solution worked perfectly.



    Regarding the 2nd solution, instead of explicitly casting each value in each row into double precision, we can apply the type cast to the column name as in the code below:



    select * from crosstab(
    $$
    select datetime, trace, value::double precision from
    (values
    (1546300800, 187923, 1.5),
    (1546300800, 187924, 200),
    (1546300800, 187926, 120),
    (1546300800, 187927, 100),
    (1546387200, 187923, 1.5),
    (1546387200, 187924, 250),
    (1546387200, 187926, 120),
    (1546387200, 187927, 125),
    (1546473600, 187923, 1.5),
    (1546473600, 187924, 275),
    (1546473600, 187926, 120),
    (1546473600, 187927, 137.5),
    (1546560000, 187923, 1.75)
    ) as t (datetime, trace, value)
    $$
    )
    as final_result (
    unixdatetime int,
    trace1 double precision,
    trace2 double precision,
    trace3 double precision,
    trace4 double precision
    )





    share|improve this answer























    • D'OH! Of course. Thanx for the reminder! :-)

      – Ancoron
      Mar 22 at 20:23











    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%2f55285661%2fpostgresql-return-and-sql-tuple-descriptions-are-incompatible%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Although you didn't mention which error you are getting, this is how to make it work:



    Initialize the module tablefunc:



    CREATE EXTENSION tablefunc;


    Then, you need to be careful about the data types. PostgreSQL can be quite picky and doesn't auto-magically convert them in many cases. In this case, they must match or at least the crosstab column type definitions must be able to completely contain the types as returned by the crosstab function SQL.



    You have 2 options here:



    1. Adapt the outer type to a variable numeric type, e.g. decimal:

    select * from crosstab(
    $$
    select * from (values
    (1546300800, 187923, 1.5),
    (1546300800, 187924, 200),
    (1546300800, 187926, 120),
    (1546300800, 187927, 100),
    (1546387200, 187923, 1.5),
    (1546387200, 187924, 250),
    (1546387200, 187926, 120),
    (1546387200, 187927, 125),
    (1546473600, 187923, 1.5),
    (1546473600, 187924, 275),
    (1546473600, 187926, 120),
    (1546473600, 187927, 137.5),
    (1546560000, 187923, 1.75)
    ) as t (datetime, trace, value)
    $$
    ) as final_result (
    unixdatetime int,
    trace1 decimal,
    trace2 decimal,
    trace3 decimal,
    trace4 decimal
    );


    1. Alternatively, make sure the crosstab SQL returns the desired type explicitly, e.g.:

    select * from crosstab(
    $$
    select * from (values
    (1546300800, 187923, 1.5::double precision),
    (1546300800, 187924, 200::double precision),
    (1546300800, 187926, 120::double precision),
    (1546300800, 187927, 100::double precision),
    (1546387200, 187923, 1.5::double precision),
    (1546387200, 187924, 250::double precision),
    (1546387200, 187926, 120::double precision),
    (1546387200, 187927, 125::double precision),
    (1546473600, 187923, 1.5::double precision),
    (1546473600, 187924, 275::double precision),
    (1546473600, 187926, 120::double precision),
    (1546473600, 187927, 137.5::double precision),
    (1546560000, 187923, 1.75::double precision)
    ) as t (datetime, trace, value)
    $$
    ) as final_result (
    unixdatetime int,
    trace1 double precision,
    trace2 double precision,
    trace3 double precision,
    trace4 double precision
    );


    The result in both cases looks as follows:



     unixdatetime | trace1 | trace2 | trace3 | trace4 
    --------------+--------+--------+--------+--------
    1546300800 | 1.5 | 200 | 120 | 100
    1546387200 | 1.5 | 250 | 120 | 125
    1546473600 | 1.5 | 275 | 120 | 137.5
    1546560000 | 1.75 | | |
    (4 rows)





    share|improve this answer



























      1














      Although you didn't mention which error you are getting, this is how to make it work:



      Initialize the module tablefunc:



      CREATE EXTENSION tablefunc;


      Then, you need to be careful about the data types. PostgreSQL can be quite picky and doesn't auto-magically convert them in many cases. In this case, they must match or at least the crosstab column type definitions must be able to completely contain the types as returned by the crosstab function SQL.



      You have 2 options here:



      1. Adapt the outer type to a variable numeric type, e.g. decimal:

      select * from crosstab(
      $$
      select * from (values
      (1546300800, 187923, 1.5),
      (1546300800, 187924, 200),
      (1546300800, 187926, 120),
      (1546300800, 187927, 100),
      (1546387200, 187923, 1.5),
      (1546387200, 187924, 250),
      (1546387200, 187926, 120),
      (1546387200, 187927, 125),
      (1546473600, 187923, 1.5),
      (1546473600, 187924, 275),
      (1546473600, 187926, 120),
      (1546473600, 187927, 137.5),
      (1546560000, 187923, 1.75)
      ) as t (datetime, trace, value)
      $$
      ) as final_result (
      unixdatetime int,
      trace1 decimal,
      trace2 decimal,
      trace3 decimal,
      trace4 decimal
      );


      1. Alternatively, make sure the crosstab SQL returns the desired type explicitly, e.g.:

      select * from crosstab(
      $$
      select * from (values
      (1546300800, 187923, 1.5::double precision),
      (1546300800, 187924, 200::double precision),
      (1546300800, 187926, 120::double precision),
      (1546300800, 187927, 100::double precision),
      (1546387200, 187923, 1.5::double precision),
      (1546387200, 187924, 250::double precision),
      (1546387200, 187926, 120::double precision),
      (1546387200, 187927, 125::double precision),
      (1546473600, 187923, 1.5::double precision),
      (1546473600, 187924, 275::double precision),
      (1546473600, 187926, 120::double precision),
      (1546473600, 187927, 137.5::double precision),
      (1546560000, 187923, 1.75::double precision)
      ) as t (datetime, trace, value)
      $$
      ) as final_result (
      unixdatetime int,
      trace1 double precision,
      trace2 double precision,
      trace3 double precision,
      trace4 double precision
      );


      The result in both cases looks as follows:



       unixdatetime | trace1 | trace2 | trace3 | trace4 
      --------------+--------+--------+--------+--------
      1546300800 | 1.5 | 200 | 120 | 100
      1546387200 | 1.5 | 250 | 120 | 125
      1546473600 | 1.5 | 275 | 120 | 137.5
      1546560000 | 1.75 | | |
      (4 rows)





      share|improve this answer

























        1












        1








        1







        Although you didn't mention which error you are getting, this is how to make it work:



        Initialize the module tablefunc:



        CREATE EXTENSION tablefunc;


        Then, you need to be careful about the data types. PostgreSQL can be quite picky and doesn't auto-magically convert them in many cases. In this case, they must match or at least the crosstab column type definitions must be able to completely contain the types as returned by the crosstab function SQL.



        You have 2 options here:



        1. Adapt the outer type to a variable numeric type, e.g. decimal:

        select * from crosstab(
        $$
        select * from (values
        (1546300800, 187923, 1.5),
        (1546300800, 187924, 200),
        (1546300800, 187926, 120),
        (1546300800, 187927, 100),
        (1546387200, 187923, 1.5),
        (1546387200, 187924, 250),
        (1546387200, 187926, 120),
        (1546387200, 187927, 125),
        (1546473600, 187923, 1.5),
        (1546473600, 187924, 275),
        (1546473600, 187926, 120),
        (1546473600, 187927, 137.5),
        (1546560000, 187923, 1.75)
        ) as t (datetime, trace, value)
        $$
        ) as final_result (
        unixdatetime int,
        trace1 decimal,
        trace2 decimal,
        trace3 decimal,
        trace4 decimal
        );


        1. Alternatively, make sure the crosstab SQL returns the desired type explicitly, e.g.:

        select * from crosstab(
        $$
        select * from (values
        (1546300800, 187923, 1.5::double precision),
        (1546300800, 187924, 200::double precision),
        (1546300800, 187926, 120::double precision),
        (1546300800, 187927, 100::double precision),
        (1546387200, 187923, 1.5::double precision),
        (1546387200, 187924, 250::double precision),
        (1546387200, 187926, 120::double precision),
        (1546387200, 187927, 125::double precision),
        (1546473600, 187923, 1.5::double precision),
        (1546473600, 187924, 275::double precision),
        (1546473600, 187926, 120::double precision),
        (1546473600, 187927, 137.5::double precision),
        (1546560000, 187923, 1.75::double precision)
        ) as t (datetime, trace, value)
        $$
        ) as final_result (
        unixdatetime int,
        trace1 double precision,
        trace2 double precision,
        trace3 double precision,
        trace4 double precision
        );


        The result in both cases looks as follows:



         unixdatetime | trace1 | trace2 | trace3 | trace4 
        --------------+--------+--------+--------+--------
        1546300800 | 1.5 | 200 | 120 | 100
        1546387200 | 1.5 | 250 | 120 | 125
        1546473600 | 1.5 | 275 | 120 | 137.5
        1546560000 | 1.75 | | |
        (4 rows)





        share|improve this answer













        Although you didn't mention which error you are getting, this is how to make it work:



        Initialize the module tablefunc:



        CREATE EXTENSION tablefunc;


        Then, you need to be careful about the data types. PostgreSQL can be quite picky and doesn't auto-magically convert them in many cases. In this case, they must match or at least the crosstab column type definitions must be able to completely contain the types as returned by the crosstab function SQL.



        You have 2 options here:



        1. Adapt the outer type to a variable numeric type, e.g. decimal:

        select * from crosstab(
        $$
        select * from (values
        (1546300800, 187923, 1.5),
        (1546300800, 187924, 200),
        (1546300800, 187926, 120),
        (1546300800, 187927, 100),
        (1546387200, 187923, 1.5),
        (1546387200, 187924, 250),
        (1546387200, 187926, 120),
        (1546387200, 187927, 125),
        (1546473600, 187923, 1.5),
        (1546473600, 187924, 275),
        (1546473600, 187926, 120),
        (1546473600, 187927, 137.5),
        (1546560000, 187923, 1.75)
        ) as t (datetime, trace, value)
        $$
        ) as final_result (
        unixdatetime int,
        trace1 decimal,
        trace2 decimal,
        trace3 decimal,
        trace4 decimal
        );


        1. Alternatively, make sure the crosstab SQL returns the desired type explicitly, e.g.:

        select * from crosstab(
        $$
        select * from (values
        (1546300800, 187923, 1.5::double precision),
        (1546300800, 187924, 200::double precision),
        (1546300800, 187926, 120::double precision),
        (1546300800, 187927, 100::double precision),
        (1546387200, 187923, 1.5::double precision),
        (1546387200, 187924, 250::double precision),
        (1546387200, 187926, 120::double precision),
        (1546387200, 187927, 125::double precision),
        (1546473600, 187923, 1.5::double precision),
        (1546473600, 187924, 275::double precision),
        (1546473600, 187926, 120::double precision),
        (1546473600, 187927, 137.5::double precision),
        (1546560000, 187923, 1.75::double precision)
        ) as t (datetime, trace, value)
        $$
        ) as final_result (
        unixdatetime int,
        trace1 double precision,
        trace2 double precision,
        trace3 double precision,
        trace4 double precision
        );


        The result in both cases looks as follows:



         unixdatetime | trace1 | trace2 | trace3 | trace4 
        --------------+--------+--------+--------+--------
        1546300800 | 1.5 | 200 | 120 | 100
        1546387200 | 1.5 | 250 | 120 | 125
        1546473600 | 1.5 | 275 | 120 | 137.5
        1546560000 | 1.75 | | |
        (4 rows)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 21 at 20:11









        AncoronAncoron

        49018




        49018























            1














            Thank you guys for the help! Ancoron's solution worked perfectly.



            Regarding the 2nd solution, instead of explicitly casting each value in each row into double precision, we can apply the type cast to the column name as in the code below:



            select * from crosstab(
            $$
            select datetime, trace, value::double precision from
            (values
            (1546300800, 187923, 1.5),
            (1546300800, 187924, 200),
            (1546300800, 187926, 120),
            (1546300800, 187927, 100),
            (1546387200, 187923, 1.5),
            (1546387200, 187924, 250),
            (1546387200, 187926, 120),
            (1546387200, 187927, 125),
            (1546473600, 187923, 1.5),
            (1546473600, 187924, 275),
            (1546473600, 187926, 120),
            (1546473600, 187927, 137.5),
            (1546560000, 187923, 1.75)
            ) as t (datetime, trace, value)
            $$
            )
            as final_result (
            unixdatetime int,
            trace1 double precision,
            trace2 double precision,
            trace3 double precision,
            trace4 double precision
            )





            share|improve this answer























            • D'OH! Of course. Thanx for the reminder! :-)

              – Ancoron
              Mar 22 at 20:23















            1














            Thank you guys for the help! Ancoron's solution worked perfectly.



            Regarding the 2nd solution, instead of explicitly casting each value in each row into double precision, we can apply the type cast to the column name as in the code below:



            select * from crosstab(
            $$
            select datetime, trace, value::double precision from
            (values
            (1546300800, 187923, 1.5),
            (1546300800, 187924, 200),
            (1546300800, 187926, 120),
            (1546300800, 187927, 100),
            (1546387200, 187923, 1.5),
            (1546387200, 187924, 250),
            (1546387200, 187926, 120),
            (1546387200, 187927, 125),
            (1546473600, 187923, 1.5),
            (1546473600, 187924, 275),
            (1546473600, 187926, 120),
            (1546473600, 187927, 137.5),
            (1546560000, 187923, 1.75)
            ) as t (datetime, trace, value)
            $$
            )
            as final_result (
            unixdatetime int,
            trace1 double precision,
            trace2 double precision,
            trace3 double precision,
            trace4 double precision
            )





            share|improve this answer























            • D'OH! Of course. Thanx for the reminder! :-)

              – Ancoron
              Mar 22 at 20:23













            1












            1








            1







            Thank you guys for the help! Ancoron's solution worked perfectly.



            Regarding the 2nd solution, instead of explicitly casting each value in each row into double precision, we can apply the type cast to the column name as in the code below:



            select * from crosstab(
            $$
            select datetime, trace, value::double precision from
            (values
            (1546300800, 187923, 1.5),
            (1546300800, 187924, 200),
            (1546300800, 187926, 120),
            (1546300800, 187927, 100),
            (1546387200, 187923, 1.5),
            (1546387200, 187924, 250),
            (1546387200, 187926, 120),
            (1546387200, 187927, 125),
            (1546473600, 187923, 1.5),
            (1546473600, 187924, 275),
            (1546473600, 187926, 120),
            (1546473600, 187927, 137.5),
            (1546560000, 187923, 1.75)
            ) as t (datetime, trace, value)
            $$
            )
            as final_result (
            unixdatetime int,
            trace1 double precision,
            trace2 double precision,
            trace3 double precision,
            trace4 double precision
            )





            share|improve this answer













            Thank you guys for the help! Ancoron's solution worked perfectly.



            Regarding the 2nd solution, instead of explicitly casting each value in each row into double precision, we can apply the type cast to the column name as in the code below:



            select * from crosstab(
            $$
            select datetime, trace, value::double precision from
            (values
            (1546300800, 187923, 1.5),
            (1546300800, 187924, 200),
            (1546300800, 187926, 120),
            (1546300800, 187927, 100),
            (1546387200, 187923, 1.5),
            (1546387200, 187924, 250),
            (1546387200, 187926, 120),
            (1546387200, 187927, 125),
            (1546473600, 187923, 1.5),
            (1546473600, 187924, 275),
            (1546473600, 187926, 120),
            (1546473600, 187927, 137.5),
            (1546560000, 187923, 1.75)
            ) as t (datetime, trace, value)
            $$
            )
            as final_result (
            unixdatetime int,
            trace1 double precision,
            trace2 double precision,
            trace3 double precision,
            trace4 double precision
            )






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 22 at 9:36









            Quy Vu XuanQuy Vu Xuan

            296




            296












            • D'OH! Of course. Thanx for the reminder! :-)

              – Ancoron
              Mar 22 at 20:23

















            • D'OH! Of course. Thanx for the reminder! :-)

              – Ancoron
              Mar 22 at 20:23
















            D'OH! Of course. Thanx for the reminder! :-)

            – Ancoron
            Mar 22 at 20:23





            D'OH! Of course. Thanx for the reminder! :-)

            – Ancoron
            Mar 22 at 20:23

















            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%2f55285661%2fpostgresql-return-and-sql-tuple-descriptions-are-incompatible%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

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현