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

  • Home
  • SEARCH
  • 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 8714551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:37:27+00:00 2026-06-13T05:37:27+00:00

I searched for a long time for the answer and did the following: (1)

  • 0

I searched for a long time for the answer and did the following:

(1)

query = "SELECT COUNT(*) FROM %s WHERE user_name = %s" % (table_name, username)
result = conn.query(query).result()[0][0]
if result == 0:
    (do something)

(2)

query = "SELECT 1 FROM %s WHERE user_name = %s" %(table_name, username)
result = conn.query(query).result()[0][0]
if result == ' ':
    (do something)

(3)

query = "SELECT EXISTS (SELECT 1 FROM %s WHERE user_name = %s)" %(table_name, username)
result = conn.query(query).result()[0][0]
if result == 't':
    (do something)

But all don’t work… the error is always:

column "Tom" does not exist

Since it really doesn’t exist and I just want to check if it exists. Any help is appreciated.

  • 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-13T05:37:29+00:00Added an answer on June 13, 2026 at 5:37 am

    You’re not quoting your strings.

    You query looks like this, once it gets to PostgreSQL:

    SELECT COUNT(*) FROM Table WHERE user_name = Tom
    

    Which compares the user_name column against the non-existant Tom column.

    What you want is a query like this:

    SELECT COUNT(*) FROM Table WHERE user_name = 'Tom'
    

    To do this right, you should be using parameterized statements, to avoid any possibility of SQL injection. With a DBAPI module, it’s a simple as:

    cursor = conn.cursor()
    cursor.execute('SELECT COUNT(*) FROM Table WHERE user_name = %s', user_name)
    

    If you need the table name to be dynamic as well, then you have to construct it like this:

    cursor = conn.cursor()
    query = 'SELECT COUNT(*) FROM %s WHERE user_name = %%s' % table_name
    cursor.execute(query, user_name)
    

    But you need to be absolutely certain that the table name is valid. Anybody who could control that variable could do absolutely anything to your database.

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

Sidebar

Related Questions

I have searched for this for a long time now... I am writing an
I am stuck with this issue for a long time. I searched for this
I've searched stackoverflow all day long to find an answer without luck, so here
I have a newbie question - I searched the web for a long time
I've searched a long time and don't found an solution here yet. Also this
I searched for a long time, but I don't manage to retrieve two related
I'm searched for a long time how to do a simple string manipulation in
I really searched for a long time to get the clue how to add
I have this problem for a long time now, I have searched the web
I've searched about the size of a java object for a long time, there

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.