Repository navigation
Datastore.select - does it work with column names that have solely integers? #810
Description
Activity
// @pcostell
Projection queries in Datastore are a little different compared to a traditional SQL projection. In particular, the projection only works if it is being run on an index (in fact, this is why we offer projection queries, so that the query only needs to perform an index scan and not the accompanied entity lookup).
In the case of
transaction.select(['date','4820477751066624']);, you would need to have an index on (Date, 4820477751066624) to perform the query. However, given the automatic indexestransaction.select(['4820477751066624']);should work.Taking your advice and using
GCloud v.0.18, here is the query:Datastore.query({ namespace: 'accounts', path: [ pathmap[ req.query.metric ] ], select: [n], filter: { "date >=": req.query.ds || m.startOf('month').unix(), "date <=": req.query.de || m.endOf('month').unix() } }, function (error, stats) { console.dir(error); });
Here is the transaction object before it is sent to the Datastore servers:
{ namespace: 'accounts', kinds: [ 'analytics' ], filters: [ { name: 'date', op: '>=', val: 1438408800 }, { name: 'date', op: '<=', val: 1441087199 } ] ] orders: [], groupByVal: [], selectVal: [ '5666823336886272' ], autoPaginateVal: true, startVal: null, endVal: null, limitVal: -1, offsetVal: -1, ... [fns] }
And here is the response:
{ error: { code: 412, message: 'Precondition Failed' } }
Using the same code I can make a query and select the
datecolumn and it works. And yes I have noticed that everything is auto-indexed, so that is why I was hoping we could query byaccountnumber.You can query by
datein this case because it is already part of the index you are using (due to the inequality).In order to answer this query, you would need an index on
(date, 5666823336886272).Okay, I get it, thank you.
- added a commit that references this issue
on Nov 10, 2022 - added 2 commits that reference this issue
on Jan 28, 2026 - added 2 commits that reference this issue
on Feb 17, 2026 - added a commit that references this issue
on Feb 26, 2026
Hey dev team, we have a Datastore table like this:

As you can see, the column names are integers, i.e. IDs mapping to individual rows within another
namespace > path.Using the code found in this issue, I am able to select a column with a name like
date, but not a column with a name like4820477751066624.Is it generally assumed that column names are
stringswith at least one letter as the starting character? Or can there be solely integer column names?Here is my Datastore response:
I have double-triple checked to make sure I run the query using an integer that is definitely a column name for the table pictured above.
Thanks in advance for your help!