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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:09:44+00:00 2026-06-07T07:09:44+00:00

Is there a difference between ndb.gql and ndb.query ? (beside the syntax) for example

  • 0

Is there a difference between ndb.gql and ndb.query? (beside the syntax)

for example

cursor = ndb.gql("select * from Account")

vs

cursor = Account.query()

I like the ndb.query because I think it’s more readable

example:

acc = Account.query(
    Account.username == form.username.data,
    Account.password == form.password.data)

I could not find any information if these two methods are different/equal under the hood.

Maybe there is a performance tradeoff?

If you are accustomed to SQL, beware of false assumptions when using
GQL. GQL is translated to NDB’s native query API. This is different
from a typical Object-Relational mapper (like SQLAlchemy or Django’s
database support), where the API calls are translated into SQL before
they are transmitted to the database server. GQL does not support
Datastore modifications (inserts, deletes or updates); it only
supports queries.

I guess that ndb.query should be "faster" because it does not need to be "translated to NDB’s native query API" right?

  • 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-07T07:09:47+00:00Added an answer on June 7, 2026 at 7:09 am

    These are simply two different ways to do the same thing. Choose whichever is easier for you in a particular situation. You’re right that gql() is theoretically slower because it builds up a Query object after parsing, but I don’t think you’ll be able to notice any difference in speed (assuming you actually run the query :-).

    Note that both return an object of the same type:

    >>> q1 = Employee.query()
    >>> q1
    Query(kind='Employee')
    >>> q2 = gql('SELECT * FROM Employee')
    >>> q2
    Query(kind='Employee', default_options=QueryOptions(offset=0))
    >>> 
    

    (The default_options field is only relevant when you use the OFFSET or LIMIT syntax in GQL.)

    So what you can do with the result is exactly the same. You can even apply additional filters and orders to q2 using the .filter() and .order() methods.

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

Sidebar

Related Questions

Is there much difference between these 2 if the manipulation is identical? In example
Is there difference between these two async JavaScript loading methods? <div class="g-plusone"></div> <script type="text/javascript">
On an int column, is there difference between doing.. SELECT .. int = '1'
Is there a difference between the two? For example within a hibernate transaction we
Is there a difference between directly downloading a file from a web server, and
Is there any difference between auto-implemented properties and manually implemented ones, from a performance
Is there any difference between these three methods to remove an element from a
Is there any difference between ReferencePath with condition '%(CopyLocal)'=='true' and ReferenceCopyLocalPaths ? The question
Is there a difference between this.form and document.forms (document[forms]) or, are they similar? Here
Is there any difference between: public ActionResult logOff() { FormsAuth.SignOut(); return RedirectToAction(index, Home); }

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.