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 650427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:03:06+00:00 2026-05-13T22:03:06+00:00

This query works: item = db.GqlQuery(SELECT * FROM Item WHERE CSIN = 13)[0] although

  • 0

This query works:

item = db.GqlQuery("SELECT * FROM Item WHERE CSIN = 13")[0]

although if there are no results returned, it blows up in my face. (How can I get around this? A for loop seems dubious when I want at max one iteration.)

This query does not work:

item = db.GqlQuery("SELECT * FROM Item WHERE CSIN = :1", CSIN)[0]

CSIN is a string representing a number. I get this error:

Traceback (most recent call last):
  File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 507, in __call__
    handler.get(*groups)
  File "path\to\src\Main.py", line 42, in get
    item = db.GqlQuery("SELECT * FROM Item WHERE CSIN = :1", CSIN)[0]
  File "C:\Program Files\Google\google_appengine\google\appengine\ext\db\__init__.py", line 1717, in __getitem__
    raise IndexError('The query returned fewer than %d results' % (arg+1))
IndexError: The query returned fewer than 1 results

What am I doing wrong here?

  • 1 1 Answer
  • 1 View
  • 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-05-13T22:03:06+00:00Added an answer on May 13, 2026 at 10:03 pm

    You’re trying to get an item from a list (or a list-like object) that is empty. What you’re doing is sort of comparable to the following:

    >>> results = [] # an empty list
    >>> item = results[0] # Raises an IndexError, because there is nothing in the list
    

    What you need to do instead is:

    item = db.GqlQuery("SELECT * FROM Item WHERE CSIN = :1", CSIN).get()
    

    Then, item will be either None or the first result from the query.

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

Sidebar

Related Questions

This query works fine for me: $query = SELECT p.topnode_id, p.param_key, p.param_value FROM tbl_params
I've got this query that works ok, select * from Materia where Cursar_Cursada=0 and
So I have this query that works perfectly: SELECT users.*, GROUP_CONCAT(categories.category_name) AS categories FROM
I have this linq query that works well (although it may be written better,
This has to be obtained from a remote machine. The following query works not
i am working on the following query:- SELECT group,item,buffer,stock,(stock-buffer) AS shortexcess FROM stkmain, stkbalance,
How can I get something like this MYSQL query with createCriteria in grails? SELECT
I have the following SQL query that works like a champ: select u.id from
I have problems running a dynamic LIKE statement in my project: this query works
I have a problem with a query. This query works with phpMyAdmin, but I

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.