Why is Django Paramaterized query not working
I have been struggling with this simple query in django. I have checked a lot over internet. I tried using similar syntax - yet no luck.
In my application on html page I need to display some specific record. And for that i want to use parameterized select statement. But the query is not working..
I have checked id2 is getting correct value from previous html page..
And I know I can use APIs but for my databases classes I need to use raw queries in my application.
Can someone please help me here...
def details(request, id2):
temp = 'test3'
data = Posts.objects.raw('''select * from posts_posts where posts_posts.id = %s ''', id2)
context ={
'post' : data,
django django-models
add a comment |
I have been struggling with this simple query in django. I have checked a lot over internet. I tried using similar syntax - yet no luck.
In my application on html page I need to display some specific record. And for that i want to use parameterized select statement. But the query is not working..
I have checked id2 is getting correct value from previous html page..
And I know I can use APIs but for my databases classes I need to use raw queries in my application.
Can someone please help me here...
def details(request, id2):
temp = 'test3'
data = Posts.objects.raw('''select * from posts_posts where posts_posts.id = %s ''', id2)
context ={
'post' : data,
django django-models
Hi, it's not clear for me what's your issue actually.
– Linovia
Nov 21 '18 at 21:12
Hi..I am trying to fecth data from postgresql and print that on html page.However the query is not working correctly. No data is getting selected. The simple select query is working fine but this parameterized query is not working correctly.
– sukhada sheth
Nov 21 '18 at 23:42
This is completely pointless. There's no need for a raw query here. You should doPost.objects.filter(id=2).
– Daniel Roseman
Nov 22 '18 at 9:34
yes i agree... as i already mentioned in my original post...this assignmnet is for my database management class...i cannot use direct APIs... I am supposed to use raw queries...
– sukhada sheth
Nov 22 '18 at 15:43
add a comment |
I have been struggling with this simple query in django. I have checked a lot over internet. I tried using similar syntax - yet no luck.
In my application on html page I need to display some specific record. And for that i want to use parameterized select statement. But the query is not working..
I have checked id2 is getting correct value from previous html page..
And I know I can use APIs but for my databases classes I need to use raw queries in my application.
Can someone please help me here...
def details(request, id2):
temp = 'test3'
data = Posts.objects.raw('''select * from posts_posts where posts_posts.id = %s ''', id2)
context ={
'post' : data,
django django-models
I have been struggling with this simple query in django. I have checked a lot over internet. I tried using similar syntax - yet no luck.
In my application on html page I need to display some specific record. And for that i want to use parameterized select statement. But the query is not working..
I have checked id2 is getting correct value from previous html page..
And I know I can use APIs but for my databases classes I need to use raw queries in my application.
Can someone please help me here...
def details(request, id2):
temp = 'test3'
data = Posts.objects.raw('''select * from posts_posts where posts_posts.id = %s ''', id2)
context ={
'post' : data,
django django-models
django django-models
edited Nov 22 '18 at 8:17
Andrew Backer
4,76623459
4,76623459
asked Nov 21 '18 at 19:17
sukhada shethsukhada sheth
81
81
Hi, it's not clear for me what's your issue actually.
– Linovia
Nov 21 '18 at 21:12
Hi..I am trying to fecth data from postgresql and print that on html page.However the query is not working correctly. No data is getting selected. The simple select query is working fine but this parameterized query is not working correctly.
– sukhada sheth
Nov 21 '18 at 23:42
This is completely pointless. There's no need for a raw query here. You should doPost.objects.filter(id=2).
– Daniel Roseman
Nov 22 '18 at 9:34
yes i agree... as i already mentioned in my original post...this assignmnet is for my database management class...i cannot use direct APIs... I am supposed to use raw queries...
– sukhada sheth
Nov 22 '18 at 15:43
add a comment |
Hi, it's not clear for me what's your issue actually.
– Linovia
Nov 21 '18 at 21:12
Hi..I am trying to fecth data from postgresql and print that on html page.However the query is not working correctly. No data is getting selected. The simple select query is working fine but this parameterized query is not working correctly.
– sukhada sheth
Nov 21 '18 at 23:42
This is completely pointless. There's no need for a raw query here. You should doPost.objects.filter(id=2).
– Daniel Roseman
Nov 22 '18 at 9:34
yes i agree... as i already mentioned in my original post...this assignmnet is for my database management class...i cannot use direct APIs... I am supposed to use raw queries...
– sukhada sheth
Nov 22 '18 at 15:43
Hi, it's not clear for me what's your issue actually.
– Linovia
Nov 21 '18 at 21:12
Hi, it's not clear for me what's your issue actually.
– Linovia
Nov 21 '18 at 21:12
Hi..I am trying to fecth data from postgresql and print that on html page.However the query is not working correctly. No data is getting selected. The simple select query is working fine but this parameterized query is not working correctly.
– sukhada sheth
Nov 21 '18 at 23:42
Hi..I am trying to fecth data from postgresql and print that on html page.However the query is not working correctly. No data is getting selected. The simple select query is working fine but this parameterized query is not working correctly.
– sukhada sheth
Nov 21 '18 at 23:42
This is completely pointless. There's no need for a raw query here. You should do
Post.objects.filter(id=2).– Daniel Roseman
Nov 22 '18 at 9:34
This is completely pointless. There's no need for a raw query here. You should do
Post.objects.filter(id=2).– Daniel Roseman
Nov 22 '18 at 9:34
yes i agree... as i already mentioned in my original post...this assignmnet is for my database management class...i cannot use direct APIs... I am supposed to use raw queries...
– sukhada sheth
Nov 22 '18 at 15:43
yes i agree... as i already mentioned in my original post...this assignmnet is for my database management class...i cannot use direct APIs... I am supposed to use raw queries...
– sukhada sheth
Nov 22 '18 at 15:43
add a comment |
1 Answer
1
active
oldest
votes
If you run that code you will see an error, since that is not the correct format for a call to raw. If you can't see the error output anywhere, then you have yet another problem for another post.
The correct format for raw is: .raw(sql, iterable-values), like this:
posts = Posts.objects.raw("select * ..", [id2, ]) # or use (id2,) for a tuple
<RawQuerySet: select * from ... where id = 5>
To get the actual list, since that just gives you a Query, you need to evaluate it somehow:
posts_list = list(posts)
first_post = posts[0]
Be careful, if you don't evaluate the QuerySet then it can be re-run a second time. Please convert it to a list() before doing further operations on it.
thanks a ton...your suggestion to evaluate the query helped. :)
– sukhada sheth
Dec 3 '18 at 21:00
Welcome to Stack Overflow! Please remember to upvote questions you find helpful, and make any responses as "answered" if they solve your issue.
– Andrew Backer
Dec 4 '18 at 3:37
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419115%2fwhy-is-django-paramaterized-query-not-working%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
If you run that code you will see an error, since that is not the correct format for a call to raw. If you can't see the error output anywhere, then you have yet another problem for another post.
The correct format for raw is: .raw(sql, iterable-values), like this:
posts = Posts.objects.raw("select * ..", [id2, ]) # or use (id2,) for a tuple
<RawQuerySet: select * from ... where id = 5>
To get the actual list, since that just gives you a Query, you need to evaluate it somehow:
posts_list = list(posts)
first_post = posts[0]
Be careful, if you don't evaluate the QuerySet then it can be re-run a second time. Please convert it to a list() before doing further operations on it.
thanks a ton...your suggestion to evaluate the query helped. :)
– sukhada sheth
Dec 3 '18 at 21:00
Welcome to Stack Overflow! Please remember to upvote questions you find helpful, and make any responses as "answered" if they solve your issue.
– Andrew Backer
Dec 4 '18 at 3:37
add a comment |
If you run that code you will see an error, since that is not the correct format for a call to raw. If you can't see the error output anywhere, then you have yet another problem for another post.
The correct format for raw is: .raw(sql, iterable-values), like this:
posts = Posts.objects.raw("select * ..", [id2, ]) # or use (id2,) for a tuple
<RawQuerySet: select * from ... where id = 5>
To get the actual list, since that just gives you a Query, you need to evaluate it somehow:
posts_list = list(posts)
first_post = posts[0]
Be careful, if you don't evaluate the QuerySet then it can be re-run a second time. Please convert it to a list() before doing further operations on it.
thanks a ton...your suggestion to evaluate the query helped. :)
– sukhada sheth
Dec 3 '18 at 21:00
Welcome to Stack Overflow! Please remember to upvote questions you find helpful, and make any responses as "answered" if they solve your issue.
– Andrew Backer
Dec 4 '18 at 3:37
add a comment |
If you run that code you will see an error, since that is not the correct format for a call to raw. If you can't see the error output anywhere, then you have yet another problem for another post.
The correct format for raw is: .raw(sql, iterable-values), like this:
posts = Posts.objects.raw("select * ..", [id2, ]) # or use (id2,) for a tuple
<RawQuerySet: select * from ... where id = 5>
To get the actual list, since that just gives you a Query, you need to evaluate it somehow:
posts_list = list(posts)
first_post = posts[0]
Be careful, if you don't evaluate the QuerySet then it can be re-run a second time. Please convert it to a list() before doing further operations on it.
If you run that code you will see an error, since that is not the correct format for a call to raw. If you can't see the error output anywhere, then you have yet another problem for another post.
The correct format for raw is: .raw(sql, iterable-values), like this:
posts = Posts.objects.raw("select * ..", [id2, ]) # or use (id2,) for a tuple
<RawQuerySet: select * from ... where id = 5>
To get the actual list, since that just gives you a Query, you need to evaluate it somehow:
posts_list = list(posts)
first_post = posts[0]
Be careful, if you don't evaluate the QuerySet then it can be re-run a second time. Please convert it to a list() before doing further operations on it.
answered Nov 22 '18 at 8:14
Andrew BackerAndrew Backer
4,76623459
4,76623459
thanks a ton...your suggestion to evaluate the query helped. :)
– sukhada sheth
Dec 3 '18 at 21:00
Welcome to Stack Overflow! Please remember to upvote questions you find helpful, and make any responses as "answered" if they solve your issue.
– Andrew Backer
Dec 4 '18 at 3:37
add a comment |
thanks a ton...your suggestion to evaluate the query helped. :)
– sukhada sheth
Dec 3 '18 at 21:00
Welcome to Stack Overflow! Please remember to upvote questions you find helpful, and make any responses as "answered" if they solve your issue.
– Andrew Backer
Dec 4 '18 at 3:37
thanks a ton...your suggestion to evaluate the query helped. :)
– sukhada sheth
Dec 3 '18 at 21:00
thanks a ton...your suggestion to evaluate the query helped. :)
– sukhada sheth
Dec 3 '18 at 21:00
Welcome to Stack Overflow! Please remember to upvote questions you find helpful, and make any responses as "answered" if they solve your issue.
– Andrew Backer
Dec 4 '18 at 3:37
Welcome to Stack Overflow! Please remember to upvote questions you find helpful, and make any responses as "answered" if they solve your issue.
– Andrew Backer
Dec 4 '18 at 3:37
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419115%2fwhy-is-django-paramaterized-query-not-working%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Hi, it's not clear for me what's your issue actually.
– Linovia
Nov 21 '18 at 21:12
Hi..I am trying to fecth data from postgresql and print that on html page.However the query is not working correctly. No data is getting selected. The simple select query is working fine but this parameterized query is not working correctly.
– sukhada sheth
Nov 21 '18 at 23:42
This is completely pointless. There's no need for a raw query here. You should do
Post.objects.filter(id=2).– Daniel Roseman
Nov 22 '18 at 9:34
yes i agree... as i already mentioned in my original post...this assignmnet is for my database management class...i cannot use direct APIs... I am supposed to use raw queries...
– sukhada sheth
Nov 22 '18 at 15:43