Cumulative aggregates produce a token unknown error












1















I have a problem with Firebird (embedded - version 3.0) database with cumulative aggregates. I have the following table:



+----+---------+
|ID |Salary +
+----+---------+
|1 |10.00 |
+----+---------+
|2 |20.00 |
+----+---------+
|3 |35.00 |
+----+---------+
|4 |10.00 |
+----+---------+


I would like to add a third column (cum_sum) that will contain a cumulative sum, i.e .:



+----+---------+---------+
|ID +Salary +cum_sum |
+----+---------+---------+
|1 |10.00 |10.00 |
+----+---------+---------+
|2 |20.00 |30.00 |
+----+---------+---------+
|3 |35.00 |65.00 |
+----+---------+---------+
|4 |10.00 |75.00 |
+----+---------+---------+


When I try to use the following code:



select id, salary, sum(salary) over (order by salary) cum_sum
from employee
order by salary


I get a message:



Invalid token.
Dynamic SQL Error.
SQL error code = -104.
Token unknown - line 1, column 37.


Where is the problem?










share|improve this question

























  • Which Firebird version are you using? Window functions were introduced in Firebird 3. Also not that your error message is incomplete, Firebird normally also reports the invalid token (in this case ().

    – Mark Rotteveel
    Nov 28 '18 at 16:30











  • I had read over the fact you say you are using Firebird 3 Embedded. I suggest you double check, because the error suggests otherwise. Try executing select rdb$get_context('SYSTEM', 'ENGINE_VERSION') from rdb$database to retrieve the actual version.

    – Mark Rotteveel
    Nov 28 '18 at 16:35











  • Minor nitpick: the expected output suggest you want to use order by id both in the window and in the main select.

    – Mark Rotteveel
    Nov 28 '18 at 16:53











  • this query is but verbatim copy of one from Firebird 3.0.0 Release Notes (page 77), so I think it can not give error in FB3. Either different server version or different query or different error it must be.

    – Arioch 'The
    Nov 28 '18 at 17:03













  • @Arioch'The You're right, but I can reproduce the exact same error message with Firebird 2.5 (that is why I knew the invalid token was ().

    – Mark Rotteveel
    Nov 28 '18 at 17:08


















1















I have a problem with Firebird (embedded - version 3.0) database with cumulative aggregates. I have the following table:



+----+---------+
|ID |Salary +
+----+---------+
|1 |10.00 |
+----+---------+
|2 |20.00 |
+----+---------+
|3 |35.00 |
+----+---------+
|4 |10.00 |
+----+---------+


I would like to add a third column (cum_sum) that will contain a cumulative sum, i.e .:



+----+---------+---------+
|ID +Salary +cum_sum |
+----+---------+---------+
|1 |10.00 |10.00 |
+----+---------+---------+
|2 |20.00 |30.00 |
+----+---------+---------+
|3 |35.00 |65.00 |
+----+---------+---------+
|4 |10.00 |75.00 |
+----+---------+---------+


When I try to use the following code:



select id, salary, sum(salary) over (order by salary) cum_sum
from employee
order by salary


I get a message:



Invalid token.
Dynamic SQL Error.
SQL error code = -104.
Token unknown - line 1, column 37.


Where is the problem?










share|improve this question

























  • Which Firebird version are you using? Window functions were introduced in Firebird 3. Also not that your error message is incomplete, Firebird normally also reports the invalid token (in this case ().

    – Mark Rotteveel
    Nov 28 '18 at 16:30











  • I had read over the fact you say you are using Firebird 3 Embedded. I suggest you double check, because the error suggests otherwise. Try executing select rdb$get_context('SYSTEM', 'ENGINE_VERSION') from rdb$database to retrieve the actual version.

    – Mark Rotteveel
    Nov 28 '18 at 16:35











  • Minor nitpick: the expected output suggest you want to use order by id both in the window and in the main select.

    – Mark Rotteveel
    Nov 28 '18 at 16:53











  • this query is but verbatim copy of one from Firebird 3.0.0 Release Notes (page 77), so I think it can not give error in FB3. Either different server version or different query or different error it must be.

    – Arioch 'The
    Nov 28 '18 at 17:03













  • @Arioch'The You're right, but I can reproduce the exact same error message with Firebird 2.5 (that is why I knew the invalid token was ().

    – Mark Rotteveel
    Nov 28 '18 at 17:08
















1












1








1








I have a problem with Firebird (embedded - version 3.0) database with cumulative aggregates. I have the following table:



+----+---------+
|ID |Salary +
+----+---------+
|1 |10.00 |
+----+---------+
|2 |20.00 |
+----+---------+
|3 |35.00 |
+----+---------+
|4 |10.00 |
+----+---------+


I would like to add a third column (cum_sum) that will contain a cumulative sum, i.e .:



+----+---------+---------+
|ID +Salary +cum_sum |
+----+---------+---------+
|1 |10.00 |10.00 |
+----+---------+---------+
|2 |20.00 |30.00 |
+----+---------+---------+
|3 |35.00 |65.00 |
+----+---------+---------+
|4 |10.00 |75.00 |
+----+---------+---------+


When I try to use the following code:



select id, salary, sum(salary) over (order by salary) cum_sum
from employee
order by salary


I get a message:



Invalid token.
Dynamic SQL Error.
SQL error code = -104.
Token unknown - line 1, column 37.


Where is the problem?










share|improve this question
















I have a problem with Firebird (embedded - version 3.0) database with cumulative aggregates. I have the following table:



+----+---------+
|ID |Salary +
+----+---------+
|1 |10.00 |
+----+---------+
|2 |20.00 |
+----+---------+
|3 |35.00 |
+----+---------+
|4 |10.00 |
+----+---------+


I would like to add a third column (cum_sum) that will contain a cumulative sum, i.e .:



+----+---------+---------+
|ID +Salary +cum_sum |
+----+---------+---------+
|1 |10.00 |10.00 |
+----+---------+---------+
|2 |20.00 |30.00 |
+----+---------+---------+
|3 |35.00 |65.00 |
+----+---------+---------+
|4 |10.00 |75.00 |
+----+---------+---------+


When I try to use the following code:



select id, salary, sum(salary) over (order by salary) cum_sum
from employee
order by salary


I get a message:



Invalid token.
Dynamic SQL Error.
SQL error code = -104.
Token unknown - line 1, column 37.


Where is the problem?







sum firebird






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 28 '18 at 16:56









Mark Rotteveel

61.5k1478122




61.5k1478122










asked Nov 28 '18 at 15:56









Mirosław RychterMirosław Rychter

182




182













  • Which Firebird version are you using? Window functions were introduced in Firebird 3. Also not that your error message is incomplete, Firebird normally also reports the invalid token (in this case ().

    – Mark Rotteveel
    Nov 28 '18 at 16:30











  • I had read over the fact you say you are using Firebird 3 Embedded. I suggest you double check, because the error suggests otherwise. Try executing select rdb$get_context('SYSTEM', 'ENGINE_VERSION') from rdb$database to retrieve the actual version.

    – Mark Rotteveel
    Nov 28 '18 at 16:35











  • Minor nitpick: the expected output suggest you want to use order by id both in the window and in the main select.

    – Mark Rotteveel
    Nov 28 '18 at 16:53











  • this query is but verbatim copy of one from Firebird 3.0.0 Release Notes (page 77), so I think it can not give error in FB3. Either different server version or different query or different error it must be.

    – Arioch 'The
    Nov 28 '18 at 17:03













  • @Arioch'The You're right, but I can reproduce the exact same error message with Firebird 2.5 (that is why I knew the invalid token was ().

    – Mark Rotteveel
    Nov 28 '18 at 17:08





















  • Which Firebird version are you using? Window functions were introduced in Firebird 3. Also not that your error message is incomplete, Firebird normally also reports the invalid token (in this case ().

    – Mark Rotteveel
    Nov 28 '18 at 16:30











  • I had read over the fact you say you are using Firebird 3 Embedded. I suggest you double check, because the error suggests otherwise. Try executing select rdb$get_context('SYSTEM', 'ENGINE_VERSION') from rdb$database to retrieve the actual version.

    – Mark Rotteveel
    Nov 28 '18 at 16:35











  • Minor nitpick: the expected output suggest you want to use order by id both in the window and in the main select.

    – Mark Rotteveel
    Nov 28 '18 at 16:53











  • this query is but verbatim copy of one from Firebird 3.0.0 Release Notes (page 77), so I think it can not give error in FB3. Either different server version or different query or different error it must be.

    – Arioch 'The
    Nov 28 '18 at 17:03













  • @Arioch'The You're right, but I can reproduce the exact same error message with Firebird 2.5 (that is why I knew the invalid token was ().

    – Mark Rotteveel
    Nov 28 '18 at 17:08



















Which Firebird version are you using? Window functions were introduced in Firebird 3. Also not that your error message is incomplete, Firebird normally also reports the invalid token (in this case ().

– Mark Rotteveel
Nov 28 '18 at 16:30





Which Firebird version are you using? Window functions were introduced in Firebird 3. Also not that your error message is incomplete, Firebird normally also reports the invalid token (in this case ().

– Mark Rotteveel
Nov 28 '18 at 16:30













I had read over the fact you say you are using Firebird 3 Embedded. I suggest you double check, because the error suggests otherwise. Try executing select rdb$get_context('SYSTEM', 'ENGINE_VERSION') from rdb$database to retrieve the actual version.

– Mark Rotteveel
Nov 28 '18 at 16:35





I had read over the fact you say you are using Firebird 3 Embedded. I suggest you double check, because the error suggests otherwise. Try executing select rdb$get_context('SYSTEM', 'ENGINE_VERSION') from rdb$database to retrieve the actual version.

– Mark Rotteveel
Nov 28 '18 at 16:35













Minor nitpick: the expected output suggest you want to use order by id both in the window and in the main select.

– Mark Rotteveel
Nov 28 '18 at 16:53





Minor nitpick: the expected output suggest you want to use order by id both in the window and in the main select.

– Mark Rotteveel
Nov 28 '18 at 16:53













this query is but verbatim copy of one from Firebird 3.0.0 Release Notes (page 77), so I think it can not give error in FB3. Either different server version or different query or different error it must be.

– Arioch 'The
Nov 28 '18 at 17:03







this query is but verbatim copy of one from Firebird 3.0.0 Release Notes (page 77), so I think it can not give error in FB3. Either different server version or different query or different error it must be.

– Arioch 'The
Nov 28 '18 at 17:03















@Arioch'The You're right, but I can reproduce the exact same error message with Firebird 2.5 (that is why I knew the invalid token was ().

– Mark Rotteveel
Nov 28 '18 at 17:08







@Arioch'The You're right, but I can reproduce the exact same error message with Firebird 2.5 (that is why I knew the invalid token was ().

– Mark Rotteveel
Nov 28 '18 at 17:08














1 Answer
1






active

oldest

votes


















1














You get this error if you are using Firebird 2.5 or earlier. Window functions were introduced in Firebird 3. You will need to upgrade to Firebird 3 if you want to run the query as shown in your question.



As you claim to use Firebird 3 Embedded, I suggest that you carefully check





  1. if your Firebird embedded version is actually version 3 (eg use select rdb$get_context('SYSTEM', 'ENGINE_VERSION') from rdb$database; this works for Firebird 2.1 and higher and will report an error for earlier versions).



    You may have loaded a different version of Firebird. This can happen if you have a different version of the embedded library earlier on the search path. This can also happen if you have a Firebird 2.5 fbembed.dll and a Firebird 3 fbclient.dll in the same location. In Firebird 3, embedded was unified with the normal client, and no longer has a separate library (it requires additional libraries, the engine plugin, instead). However most Firebird drivers will first attempt to load fbembed.dll before falling back to fbclient.dll.




  2. if you are actually connecting with Firebird embedded, and not accidentally to a Firebird server instance of a different version (eg select rdb$get_context('SYSTEM', 'NETWORK_PROTOCOL') from rdb$database will report NULL for embedded, but a value for other connection methods).



    This can happen if you use the wrong connection string or otherwise incorrectly configured your driver.




Otherwise, if you can't upgrade, you will need to use the more painful option of writing a stored procedure (or block) that does this for you, or resort to equally painful recursive CTE-based solutions (that have other limitations that might get in the way).






share|improve this answer

























    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%2f53523419%2fcumulative-aggregates-produce-a-token-unknown-error%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









    1














    You get this error if you are using Firebird 2.5 or earlier. Window functions were introduced in Firebird 3. You will need to upgrade to Firebird 3 if you want to run the query as shown in your question.



    As you claim to use Firebird 3 Embedded, I suggest that you carefully check





    1. if your Firebird embedded version is actually version 3 (eg use select rdb$get_context('SYSTEM', 'ENGINE_VERSION') from rdb$database; this works for Firebird 2.1 and higher and will report an error for earlier versions).



      You may have loaded a different version of Firebird. This can happen if you have a different version of the embedded library earlier on the search path. This can also happen if you have a Firebird 2.5 fbembed.dll and a Firebird 3 fbclient.dll in the same location. In Firebird 3, embedded was unified with the normal client, and no longer has a separate library (it requires additional libraries, the engine plugin, instead). However most Firebird drivers will first attempt to load fbembed.dll before falling back to fbclient.dll.




    2. if you are actually connecting with Firebird embedded, and not accidentally to a Firebird server instance of a different version (eg select rdb$get_context('SYSTEM', 'NETWORK_PROTOCOL') from rdb$database will report NULL for embedded, but a value for other connection methods).



      This can happen if you use the wrong connection string or otherwise incorrectly configured your driver.




    Otherwise, if you can't upgrade, you will need to use the more painful option of writing a stored procedure (or block) that does this for you, or resort to equally painful recursive CTE-based solutions (that have other limitations that might get in the way).






    share|improve this answer






























      1














      You get this error if you are using Firebird 2.5 or earlier. Window functions were introduced in Firebird 3. You will need to upgrade to Firebird 3 if you want to run the query as shown in your question.



      As you claim to use Firebird 3 Embedded, I suggest that you carefully check





      1. if your Firebird embedded version is actually version 3 (eg use select rdb$get_context('SYSTEM', 'ENGINE_VERSION') from rdb$database; this works for Firebird 2.1 and higher and will report an error for earlier versions).



        You may have loaded a different version of Firebird. This can happen if you have a different version of the embedded library earlier on the search path. This can also happen if you have a Firebird 2.5 fbembed.dll and a Firebird 3 fbclient.dll in the same location. In Firebird 3, embedded was unified with the normal client, and no longer has a separate library (it requires additional libraries, the engine plugin, instead). However most Firebird drivers will first attempt to load fbembed.dll before falling back to fbclient.dll.




      2. if you are actually connecting with Firebird embedded, and not accidentally to a Firebird server instance of a different version (eg select rdb$get_context('SYSTEM', 'NETWORK_PROTOCOL') from rdb$database will report NULL for embedded, but a value for other connection methods).



        This can happen if you use the wrong connection string or otherwise incorrectly configured your driver.




      Otherwise, if you can't upgrade, you will need to use the more painful option of writing a stored procedure (or block) that does this for you, or resort to equally painful recursive CTE-based solutions (that have other limitations that might get in the way).






      share|improve this answer




























        1












        1








        1







        You get this error if you are using Firebird 2.5 or earlier. Window functions were introduced in Firebird 3. You will need to upgrade to Firebird 3 if you want to run the query as shown in your question.



        As you claim to use Firebird 3 Embedded, I suggest that you carefully check





        1. if your Firebird embedded version is actually version 3 (eg use select rdb$get_context('SYSTEM', 'ENGINE_VERSION') from rdb$database; this works for Firebird 2.1 and higher and will report an error for earlier versions).



          You may have loaded a different version of Firebird. This can happen if you have a different version of the embedded library earlier on the search path. This can also happen if you have a Firebird 2.5 fbembed.dll and a Firebird 3 fbclient.dll in the same location. In Firebird 3, embedded was unified with the normal client, and no longer has a separate library (it requires additional libraries, the engine plugin, instead). However most Firebird drivers will first attempt to load fbembed.dll before falling back to fbclient.dll.




        2. if you are actually connecting with Firebird embedded, and not accidentally to a Firebird server instance of a different version (eg select rdb$get_context('SYSTEM', 'NETWORK_PROTOCOL') from rdb$database will report NULL for embedded, but a value for other connection methods).



          This can happen if you use the wrong connection string or otherwise incorrectly configured your driver.




        Otherwise, if you can't upgrade, you will need to use the more painful option of writing a stored procedure (or block) that does this for you, or resort to equally painful recursive CTE-based solutions (that have other limitations that might get in the way).






        share|improve this answer















        You get this error if you are using Firebird 2.5 or earlier. Window functions were introduced in Firebird 3. You will need to upgrade to Firebird 3 if you want to run the query as shown in your question.



        As you claim to use Firebird 3 Embedded, I suggest that you carefully check





        1. if your Firebird embedded version is actually version 3 (eg use select rdb$get_context('SYSTEM', 'ENGINE_VERSION') from rdb$database; this works for Firebird 2.1 and higher and will report an error for earlier versions).



          You may have loaded a different version of Firebird. This can happen if you have a different version of the embedded library earlier on the search path. This can also happen if you have a Firebird 2.5 fbembed.dll and a Firebird 3 fbclient.dll in the same location. In Firebird 3, embedded was unified with the normal client, and no longer has a separate library (it requires additional libraries, the engine plugin, instead). However most Firebird drivers will first attempt to load fbembed.dll before falling back to fbclient.dll.




        2. if you are actually connecting with Firebird embedded, and not accidentally to a Firebird server instance of a different version (eg select rdb$get_context('SYSTEM', 'NETWORK_PROTOCOL') from rdb$database will report NULL for embedded, but a value for other connection methods).



          This can happen if you use the wrong connection string or otherwise incorrectly configured your driver.




        Otherwise, if you can't upgrade, you will need to use the more painful option of writing a stored procedure (or block) that does this for you, or resort to equally painful recursive CTE-based solutions (that have other limitations that might get in the way).







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 28 '18 at 16:54

























        answered Nov 28 '18 at 16:33









        Mark RotteveelMark Rotteveel

        61.5k1478122




        61.5k1478122
































            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%2f53523419%2fcumulative-aggregates-produce-a-token-unknown-error%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

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)