Select to view content in your preferred language

When to use Query where: "1=0"

530
3
05-27-2022 01:37 PM
TimDietz
New Contributor III

Hi,

I am very new to ArcGIS and have "inherited" a project that provides a map on one of our web pages.  I am slogging through it and learning a lot, but one thing still stumps me.  This code has several instances where it sets the Query 'where' property to '1=0'.  Now, to my SQL thinking, adding a where clause such as 1=0, which evaluates to false, would return nothing.  However, I have witnessed that something does get returned when I enter the corresponding URL (like the one below).  If I change the where to '1=1' much more data is returned, however.

Can anyone please explain the purpose of using a where clause of '1=0'?

https://<URL Returning FeatureLayer>/query?f=json&where=1=0

0 Kudos
3 Replies
ReneRubalcava
Frequent Contributor II

I'm not sure why someone would want that, I suppose it depends. The query would return info about the fields, maybe some other service info, but an empty array of features.

0 Kudos
BlakeTerhune
MVP Regular Contributor

Since there's not really a true boolean value in SQL, people use 1=0 or 1=1. You would use 1=0 in some geoprocessing tools (like feature class to feature class) to copy the table structure without the data. Although you can do the same thing using the template parameter with Create Table or Create Feature Class. In the context of a JS web app, I'm not really sure why you would query where 1=0. I'd have to see it in context.

Using 1=1 will return all rows and is common in web apps when querying a feature layer in order to work with all the data.

0 Kudos
TimDietz
New Contributor III

One of the scenarios where this is used is when populating an OnDemandGrid.  After the grid is populated during initialization, there is an icon placed on the map to display the grid.

It may be that the first query (with 1=0) is used to just initialize the grid with nothing.  Later in the initialization process, the query is re-issued (with 1=1) to retrieve data and populate the grid.  I don't know, yet, but there may be scenarios where the query is never re-issued during initialization.  In that case, if we hadn't already initialized the grid, nothing would show at all.

0 Kudos