Querying for a subsequence using Django ArrayFields









up vote
0
down vote

favorite












I have an ArrayField that stores sequences of integers in it, for example: Sequences.objects.first().seq returns [5,4,4,3,2,2,1]. The sequences are always stored in decreasing order, and I want to filter Sequences to find a subsequence. However, I'm running into problems when trying to find a subsequence that contains repeated elements and I don't know how to go about solving this problem.



For instance, if I wish to filter for any sequence containing the subsequence q = [5,4,4,4,2], I would try Sequences.objects.filter(seq__contains=q), but this QuerySet will include the sequence [5,4,4,3,2,2,1], since each element of q is individually in the sequence, but not all together. However, I do not want only exact matches. If I filtered by q, I would like to include something like [6,5,5,4,4,4,3,2,1] but reject something like [5,4,4,3,2,2,1] since the former case has all of q with multiplicity, and the latter is missing a 4, and so doesnt contain q as a subsequence.










share|improve this question























  • Did you try using iexact? i.e. Sequences.objecst.filter(seq__iexact=q)
    – nara_l
    Nov 11 at 2:46










  • Thanks for asking! I don't want to use iexact and have clarified the question some.
    – Sharat Chandra
    Nov 11 at 3:00














up vote
0
down vote

favorite












I have an ArrayField that stores sequences of integers in it, for example: Sequences.objects.first().seq returns [5,4,4,3,2,2,1]. The sequences are always stored in decreasing order, and I want to filter Sequences to find a subsequence. However, I'm running into problems when trying to find a subsequence that contains repeated elements and I don't know how to go about solving this problem.



For instance, if I wish to filter for any sequence containing the subsequence q = [5,4,4,4,2], I would try Sequences.objects.filter(seq__contains=q), but this QuerySet will include the sequence [5,4,4,3,2,2,1], since each element of q is individually in the sequence, but not all together. However, I do not want only exact matches. If I filtered by q, I would like to include something like [6,5,5,4,4,4,3,2,1] but reject something like [5,4,4,3,2,2,1] since the former case has all of q with multiplicity, and the latter is missing a 4, and so doesnt contain q as a subsequence.










share|improve this question























  • Did you try using iexact? i.e. Sequences.objecst.filter(seq__iexact=q)
    – nara_l
    Nov 11 at 2:46










  • Thanks for asking! I don't want to use iexact and have clarified the question some.
    – Sharat Chandra
    Nov 11 at 3:00












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have an ArrayField that stores sequences of integers in it, for example: Sequences.objects.first().seq returns [5,4,4,3,2,2,1]. The sequences are always stored in decreasing order, and I want to filter Sequences to find a subsequence. However, I'm running into problems when trying to find a subsequence that contains repeated elements and I don't know how to go about solving this problem.



For instance, if I wish to filter for any sequence containing the subsequence q = [5,4,4,4,2], I would try Sequences.objects.filter(seq__contains=q), but this QuerySet will include the sequence [5,4,4,3,2,2,1], since each element of q is individually in the sequence, but not all together. However, I do not want only exact matches. If I filtered by q, I would like to include something like [6,5,5,4,4,4,3,2,1] but reject something like [5,4,4,3,2,2,1] since the former case has all of q with multiplicity, and the latter is missing a 4, and so doesnt contain q as a subsequence.










share|improve this question















I have an ArrayField that stores sequences of integers in it, for example: Sequences.objects.first().seq returns [5,4,4,3,2,2,1]. The sequences are always stored in decreasing order, and I want to filter Sequences to find a subsequence. However, I'm running into problems when trying to find a subsequence that contains repeated elements and I don't know how to go about solving this problem.



For instance, if I wish to filter for any sequence containing the subsequence q = [5,4,4,4,2], I would try Sequences.objects.filter(seq__contains=q), but this QuerySet will include the sequence [5,4,4,3,2,2,1], since each element of q is individually in the sequence, but not all together. However, I do not want only exact matches. If I filtered by q, I would like to include something like [6,5,5,4,4,4,3,2,1] but reject something like [5,4,4,3,2,2,1] since the former case has all of q with multiplicity, and the latter is missing a 4, and so doesnt contain q as a subsequence.







django postgresql sequence subsequence






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 2:59

























asked Nov 11 at 1:39









Sharat Chandra

12




12











  • Did you try using iexact? i.e. Sequences.objecst.filter(seq__iexact=q)
    – nara_l
    Nov 11 at 2:46










  • Thanks for asking! I don't want to use iexact and have clarified the question some.
    – Sharat Chandra
    Nov 11 at 3:00
















  • Did you try using iexact? i.e. Sequences.objecst.filter(seq__iexact=q)
    – nara_l
    Nov 11 at 2:46










  • Thanks for asking! I don't want to use iexact and have clarified the question some.
    – Sharat Chandra
    Nov 11 at 3:00















Did you try using iexact? i.e. Sequences.objecst.filter(seq__iexact=q)
– nara_l
Nov 11 at 2:46




Did you try using iexact? i.e. Sequences.objecst.filter(seq__iexact=q)
– nara_l
Nov 11 at 2:46












Thanks for asking! I don't want to use iexact and have clarified the question some.
– Sharat Chandra
Nov 11 at 3:00




Thanks for asking! I don't want to use iexact and have clarified the question some.
– Sharat Chandra
Nov 11 at 3:00

















active

oldest

votes











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%2f53245122%2fquerying-for-a-subsequence-using-django-arrayfields%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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%2f53245122%2fquerying-for-a-subsequence-using-django-arrayfields%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

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo