Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8825345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:51:20+00:00 2026-06-14T06:51:20+00:00

I have the following function in Python: def get_emo_results(emo, operator): cursor.execute(SELECT avg(?) FROM [LIWC

  • 0

I have the following function in Python:

def get_emo_results(emo, operator):
    cursor.execute("SELECT avg(?) FROM [LIWC Post Stats] "
                   "WHERE goals_scored {0} goals_taken "
                   "GROUP BY post_number "
                   "ORDER BY post_number ASC "
                   "LIMIT ?".format(operator), [emo, posts_limit])
    print "SELECT avg({1}) FROM [LIWC Post Stats] "\
            "WHERE goals_scored {0} goals_taken "\
            "GROUP BY post_number "\
            "ORDER BY post_number ASC "\
            "LIMIT {2}".format(operator, emo, posts_limit)
    return [x[0] for x in cursor.fetchall()]

I call it with get_emo_results('posemo', '>') and get this output to stdout:

SELECT avg(posemo) FROM [LIWC Post Stats] WHERE goals_scored > goals_taken GROUP BY post_number ORDER BY post_number ASC LIMIT 200

However, the function itself returns

[0.0, 0.0, 0.0, 0.0, 0.0, ... 0.0]

I copy and paste that exact expression in stdout to my SQLite process that I have opened, and I get this:

1.8730701754386
2.48962719298246
2.18607456140351
2.15342105263158
2.33107456140351
2.11631578947368
2.37100877192982
1.95228070175439
2.01013157894737
...
3.37183673469388

So not 0 at all. Why does my Python function return something different despite using the same query? What am I doing wrong?

EDIT:

It now works when I get rid of the question marks and format the string directly. Why don’t parameterized queries work in this case?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:51:22+00:00Added an answer on June 14, 2026 at 6:51 am

    It is being handled differently because you are parametirzing your query. You can’t really parameterize a column name like that. It is trying to protect you from SQL injection so it is (I’m simplifying here, but basically) encapsulating any strings in quotes before passing it to the SQL engine.

    Essentially, SQLlite is trying to average the string literal ‘posemo’

    You can keep your limit parameterized, but when it comes to column names you need to have them hardcoded or else put them in the string with something like format.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In python I have the following function: def is_a_nice_element(element, parameter): #do something return True
I have the following function in a Python module called dictbuilder.py: def my_dictbuilder(reader_o, writer):
I have the following python code: def split_arg(argv): buildDescriptor = argv[1] buildfile, target =
I have the following function: def storeTaggedCorpus(corpus, filename): corpusFile = codecs.open(filename, mode = 'w',
Suppose I have the following python code: def outer(): string = def inner(): string
i am working on a regex match function in python. i have the following
Look at the following Python code: def function(x): return x, x+1 sequence = range(5)
I have the following python function to recursively find all partitions of a set:
how do i round off a function. i have the following code in python
I have a following decorator: from decorator import decorator def my_decorator(key=None, timeout=None, retry=0): My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.