Imitate partitions/window functions in sqlkorma










3















I am trying to call the equivalent of this function using sqlkorma, and have not found the equivalent of a partition in the documentation (http://sqlkorma.com/docs):



SELECT * FROM (
SELECT DISTINCT cgi, scgi, c.id, c.name, c.address, c.city,
c.state_or_province, c.postal_code, primary_country,
ROW_NUMBER() OVER (
PARTITION BY cgi
) AS ROW_NUMBER
from ccs
join c on c.id = ccs.id) groups
WHERE groups.ROW_NUMBER = 1 ORDER BY cgi


For clarity, in my database, there is a one-to-many relationship columns variables "cgi" and "c.id"










share|improve this question
























  • What have you tried so far?

    – Progressive
    Nov 12 '18 at 22:09






  • 1





    1) Tried looking into an equivalent for "DISTINCT ON" postgresql terminology" 2) Tried aggregating data and picking the first c.id from each cgi - I don't think the aggregate modifier is the way to go 3) Tried to make the equivalent of the best answer's second query here: stackoverflow.com/questions/3800551/…

    – Monica
    Nov 12 '18 at 22:52
















3















I am trying to call the equivalent of this function using sqlkorma, and have not found the equivalent of a partition in the documentation (http://sqlkorma.com/docs):



SELECT * FROM (
SELECT DISTINCT cgi, scgi, c.id, c.name, c.address, c.city,
c.state_or_province, c.postal_code, primary_country,
ROW_NUMBER() OVER (
PARTITION BY cgi
) AS ROW_NUMBER
from ccs
join c on c.id = ccs.id) groups
WHERE groups.ROW_NUMBER = 1 ORDER BY cgi


For clarity, in my database, there is a one-to-many relationship columns variables "cgi" and "c.id"










share|improve this question
























  • What have you tried so far?

    – Progressive
    Nov 12 '18 at 22:09






  • 1





    1) Tried looking into an equivalent for "DISTINCT ON" postgresql terminology" 2) Tried aggregating data and picking the first c.id from each cgi - I don't think the aggregate modifier is the way to go 3) Tried to make the equivalent of the best answer's second query here: stackoverflow.com/questions/3800551/…

    – Monica
    Nov 12 '18 at 22:52














3












3








3








I am trying to call the equivalent of this function using sqlkorma, and have not found the equivalent of a partition in the documentation (http://sqlkorma.com/docs):



SELECT * FROM (
SELECT DISTINCT cgi, scgi, c.id, c.name, c.address, c.city,
c.state_or_province, c.postal_code, primary_country,
ROW_NUMBER() OVER (
PARTITION BY cgi
) AS ROW_NUMBER
from ccs
join c on c.id = ccs.id) groups
WHERE groups.ROW_NUMBER = 1 ORDER BY cgi


For clarity, in my database, there is a one-to-many relationship columns variables "cgi" and "c.id"










share|improve this question
















I am trying to call the equivalent of this function using sqlkorma, and have not found the equivalent of a partition in the documentation (http://sqlkorma.com/docs):



SELECT * FROM (
SELECT DISTINCT cgi, scgi, c.id, c.name, c.address, c.city,
c.state_or_province, c.postal_code, primary_country,
ROW_NUMBER() OVER (
PARTITION BY cgi
) AS ROW_NUMBER
from ccs
join c on c.id = ccs.id) groups
WHERE groups.ROW_NUMBER = 1 ORDER BY cgi


For clarity, in my database, there is a one-to-many relationship columns variables "cgi" and "c.id"







clojure korma sqlkorma






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 15:09







Monica

















asked Nov 12 '18 at 21:40









MonicaMonica

267




267












  • What have you tried so far?

    – Progressive
    Nov 12 '18 at 22:09






  • 1





    1) Tried looking into an equivalent for "DISTINCT ON" postgresql terminology" 2) Tried aggregating data and picking the first c.id from each cgi - I don't think the aggregate modifier is the way to go 3) Tried to make the equivalent of the best answer's second query here: stackoverflow.com/questions/3800551/…

    – Monica
    Nov 12 '18 at 22:52


















  • What have you tried so far?

    – Progressive
    Nov 12 '18 at 22:09






  • 1





    1) Tried looking into an equivalent for "DISTINCT ON" postgresql terminology" 2) Tried aggregating data and picking the first c.id from each cgi - I don't think the aggregate modifier is the way to go 3) Tried to make the equivalent of the best answer's second query here: stackoverflow.com/questions/3800551/…

    – Monica
    Nov 12 '18 at 22:52

















What have you tried so far?

– Progressive
Nov 12 '18 at 22:09





What have you tried so far?

– Progressive
Nov 12 '18 at 22:09




1




1





1) Tried looking into an equivalent for "DISTINCT ON" postgresql terminology" 2) Tried aggregating data and picking the first c.id from each cgi - I don't think the aggregate modifier is the way to go 3) Tried to make the equivalent of the best answer's second query here: stackoverflow.com/questions/3800551/…

– Monica
Nov 12 '18 at 22:52






1) Tried looking into an equivalent for "DISTINCT ON" postgresql terminology" 2) Tried aggregating data and picking the first c.id from each cgi - I don't think the aggregate modifier is the way to go 3) Tried to make the equivalent of the best answer's second query here: stackoverflow.com/questions/3800551/…

– Monica
Nov 12 '18 at 22:52













1 Answer
1






active

oldest

votes


















1














Found a simple solution to this - sqlkorma allows you to execute raw SQL, and I specified the postgresql DISTINCT ON (column_to_partition_on), column_to_partition_on, column1, column2 FROM table. Using that as the query text, this is the general format to execute raw sql using korma:



(exec-raw my-database query-text :results)


More info at http://sqlkorma.com/docs






share|improve this answer























  • if you end up writing raw SQL too often, you may want to check out github.com/layerware/hugsql

    – nha
    Nov 14 '18 at 19:10










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%2f53270501%2fimitate-partitions-window-functions-in-sqlkorma%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














Found a simple solution to this - sqlkorma allows you to execute raw SQL, and I specified the postgresql DISTINCT ON (column_to_partition_on), column_to_partition_on, column1, column2 FROM table. Using that as the query text, this is the general format to execute raw sql using korma:



(exec-raw my-database query-text :results)


More info at http://sqlkorma.com/docs






share|improve this answer























  • if you end up writing raw SQL too often, you may want to check out github.com/layerware/hugsql

    – nha
    Nov 14 '18 at 19:10















1














Found a simple solution to this - sqlkorma allows you to execute raw SQL, and I specified the postgresql DISTINCT ON (column_to_partition_on), column_to_partition_on, column1, column2 FROM table. Using that as the query text, this is the general format to execute raw sql using korma:



(exec-raw my-database query-text :results)


More info at http://sqlkorma.com/docs






share|improve this answer























  • if you end up writing raw SQL too often, you may want to check out github.com/layerware/hugsql

    – nha
    Nov 14 '18 at 19:10













1












1








1







Found a simple solution to this - sqlkorma allows you to execute raw SQL, and I specified the postgresql DISTINCT ON (column_to_partition_on), column_to_partition_on, column1, column2 FROM table. Using that as the query text, this is the general format to execute raw sql using korma:



(exec-raw my-database query-text :results)


More info at http://sqlkorma.com/docs






share|improve this answer













Found a simple solution to this - sqlkorma allows you to execute raw SQL, and I specified the postgresql DISTINCT ON (column_to_partition_on), column_to_partition_on, column1, column2 FROM table. Using that as the query text, this is the general format to execute raw sql using korma:



(exec-raw my-database query-text :results)


More info at http://sqlkorma.com/docs







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 21:21









MonicaMonica

267




267












  • if you end up writing raw SQL too often, you may want to check out github.com/layerware/hugsql

    – nha
    Nov 14 '18 at 19:10

















  • if you end up writing raw SQL too often, you may want to check out github.com/layerware/hugsql

    – nha
    Nov 14 '18 at 19:10
















if you end up writing raw SQL too often, you may want to check out github.com/layerware/hugsql

– nha
Nov 14 '18 at 19:10





if you end up writing raw SQL too often, you may want to check out github.com/layerware/hugsql

– nha
Nov 14 '18 at 19:10

















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%2f53270501%2fimitate-partitions-window-functions-in-sqlkorma%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

Kleinkühnau

Makov (Slowakei)

Deutsches Schauspielhaus