Questions tagged [where-clause]

A WHERE clause is used to select data conditionally, as part of a Structured Query Language (SQL) operation

Filter by
Sorted by
Tagged with
4 votes
1 answer
52 views

Extending "Join attributes by nearest" with WHERE clause in QGIS

I am using QGIS v3.24.1-Tisler and the "Join attributes by nearest" tool in Processing Toolbox, which does 90% of what I need. However I would like to be able to add a WHERE clause, so join ...
user avatar
  • 41
0 votes
1 answer
64 views

GDAL where clause failing

I have written an ogr2ogr script to convert well known text values into reprojected geometry table, however even when excluding values with the value "NULL" (as opposed to no value at all) ...
user avatar
  • 73
1 vote
0 answers
50 views

Using logical expression in ArcPy

I am trying to write a Python command that includes a logical query. I have series of tables and layers and would like to run a command on them when two shared variables have the same values. I ...
user avatar
  • 39
4 votes
1 answer
441 views

GDAL Rasterize with "where" option in Python

I've got a shapefile with set of points with a column "test_class" of String type in the attribute table. I need to rasterize these points with setting pixel's value for each class and ...
user avatar
  • 43
1 vote
1 answer
67 views

PostGIS where clause not working as expected with multipart geometry

I am running an intersect from a subset of one table on itself (this is part of a larger parameterized query but the issue in question arose out of this particular situation) using a CTE (zones in the ...
user avatar
  • 440
1 vote
3 answers
127 views

Writing MakeFeatureLayer_management Where Clause With Multiple Mixed Values using ArcPy

I am trying to select certain points in a shape file using three different fields. Two fields don't need to vary, but the third one (the analog_years variable below) does. I want to be able to select ...
user avatar
  • 33
2 votes
1 answer
61 views

FeatureClassToFeatureClass_conversion where_clause ignored in PyCharm console

When I call arcpy.FeatureClassToFeatureClass_conversion from the PyCharm python console, the where_clause argument is ignored. When a value is supplied, it does not return an error message, nor does ...
user avatar
  • 722
1 vote
1 answer
63 views

ArcPy FeatureClassToFeatureClass_conversion invalid SQL statement

I am trying to iterate through a list of where clauses as such: for vc in vcList: print (vc) """"D_Zone" = 1""" """"D_Zone" = 2&...
user avatar
  • 1,405
2 votes
1 answer
216 views

Arcpy Python Snippet for SQL "LIKE" expression problem

I am trying to use arcpy.Select_analysis in python code with ArcGIS for straightforward geoprocessing. I have a field called "other tags" in a vector dataset which I want to select any ...
user avatar
4 votes
1 answer
161 views

ArcPy TableToNumPyArray where_clause issue

I am trying to run this code in the Python terminal in ArcGIS, but everytime it throws an error and I can't figure it out. I think it probably has something do with how I construct the SQL where ...
user avatar
  • 137
1 vote
1 answer
335 views

Why do ArcPy SQL expressions use three double quotes?

I am using ArcGIS Pro 2.4 and I am trying to understand why ArcPy SQL expressions use three double quotes. ESRI's "Specifying a query in Python" page, https://pro.arcgis.com/en/pro-app/arcpy/get-...
user avatar
  • 638
2 votes
0 answers
77 views

Where_Clause expression working for one FeatureClassToFeatureClass_conversion export but not another

I am attempting to export a feature class to both a shapefile and feature class with a where_clause restriction on particular values within particular fields. I have written a function to take dataset ...
user avatar
2 votes
0 answers
488 views

SQL query fails in arcpy, but works in ArcGIS Pro 'select by attributes' [closed]

I'm building an SQL query in Python that is used to make a feature layer, but the feature layer returns no features, when it should return 1169 features. The query below works on 95% of the data (...
user avatar
2 votes
1 answer
44 views

Determining types of geometry in a single table?

I need to determine whether any tables within my database have more than one geometry type. For example, I want to know if there are Points AND multipoints within the same table. Currently, I have ...
user avatar
0 votes
0 answers
103 views

WHERE clause that's stored in a table: Use it to filter a layer?

I have a workorder management system (WMS). The WMS has functionality that allows users to save queries. The queries are saved in a Oracle database table called QUERY (in a CLAUSE column). An ...
user avatar
  • 716
1 vote
0 answers
47 views

Use selected features to generate WHERE clause in ArcGIS for Portal

I have a web map in Portal that has a point layer called Work Orders. I believe it's possible to manually select points in the layer by using the Web AppBuilder Select Widget. Using selected points, ...
user avatar
  • 716
0 votes
1 answer
91 views

Filter layer by pasting in WHERE clause?

I have a web map in Portal that has the Web AppBuilder Filter widget. The map has a point layer in it called Work Orders. I would like to filter the work orders by pasting in a WHERE clause. The ...
user avatar
  • 716
0 votes
1 answer
106 views

Creating WHERE clause from list using ArcPy

I am creating a new shapefile (a subset of a current shapefile) such that it has all the features whose values in a field ("fclass") is not contained in the field_names list. field_names = ['...
user avatar
  • 755
1 vote
3 answers
712 views

Using field in place of value in WHERE clause of arcpy.da.SearchCursor()? [closed]

I am developing an ArcPy script in ArcGIS Desktop 10.7 and using a file geodatabase feature class. I have a field called facility_id. I have tried using this field as a string field or as an integer ...
user avatar
  • 27
2 votes
0 answers
95 views

How can I validate a SQL statement in ArcObjects?

I'm trying to validate the results of a ISQLQueryDialog2, but can't find any out of the box solutions. This particular dialog has a built in validate button, but I would like to programmatically ...
user avatar
  • 5,727
0 votes
1 answer
53 views

Using keyword in SelectByAttribute expression?

I've used SearchCursor to return the single value of a record (8 digit number) for row in arcpy.da.SearchCursor(table, ['PID']): if row[0] is not None: ID = row[0] break Now I would like ...
user avatar
1 vote
1 answer
144 views

Trying to add a value in the second row of a table

I am trying to add a specific value to a cell of the second row of a feature-class-table. Doesn't work with my code: #First row rows = arcpy.InsertCursor(tb_value) row = rows.newRow() ...
user avatar
  • 69
2 votes
1 answer
58 views

Problem with if-statement and whereClause format

I have a program which should count the number of a feature class or the length of a feature class depending on the geometry of the input feature class. This part is working. There are two parameter-...
user avatar
  • 69
1 vote
2 answers
241 views

Automating Select by location using ArcPy and where_clause?

I have used the code in Coding python loop to select features of polygon layer than are completely contained in group of 11 layers using ArcPy? to automate select by location analysis using ArcPy. I ...
user avatar
1 vote
2 answers
96 views

Where Clause in SelectLayerByAttribute function resulting in invalid expression

All of the attempts below result in ERROR 000358: Invalid expression Any ideas on what I am doing wrong? I am working within a File GDB and with polygons. Attempt 1: def SelectLayer(val): print ...
user avatar
  • 1,471
0 votes
1 answer
120 views

Syntax error in Where Clause using .format in arcpy.Select_analysis

I'm having a little trouble understanding the syntax for a Where Clause; e.g., for use in arcpy.Select_analysis(inSHP, clipSHP, where). input is polygon shapefile; Zone_ID field is short integer ...
user avatar
  • 881
0 votes
1 answer
53 views

Subset a shapefile that excludes certain field values by using NOT in Select by Attribute where clause

I am using ArcPy 2.7 to subset a shapefile. I am trying to use arcpy.Select_analysis to exclude certain features from a shapefile (idle fields denoted as 1401 in the field 'Crop_Type'. my 'Crop_Type' ...
user avatar
  • 638
0 votes
1 answer
290 views

Using arcpy.makequerytable_management with where clause?

I have a script that works great with selecting dates greater than "my From date" but I can't get the code to work when I want to add a less than to the sql where clause (a to date). I had add the {0}...
user avatar
1 vote
1 answer
135 views

Setting up where_clause to select counties one at a time from feature class using ArcPy?

I need to select a single county at the time from the "counties" feature class. I am using a make feature layer with a where clause. How do I set up the where_clause to select each of the counties in ...
user avatar
1 vote
1 answer
81 views

Using IN Clause to Select By Attributes in ArcPy?

I am working in ArcMap 10.1, trying to write a script to automate the selection of a feature class. I have two input parameters: stop1 = arcpy.GetParameterAsText(0) stop2 = arcpy.GetParameterAsText(1)...
user avatar
  • 177
2 votes
1 answer
118 views

Same SQL expression works with search cursor but not make feature layer

I need to get features in a File GeoDatabase feature class whose "fieldName" (string field) value matches the value of "strValue" (string variable). While I know there are features satisfying this ...
user avatar
  • 210
5 votes
3 answers
4k views

Writing ArcPy Update Cursor "Where Clause" that Refers to its own Rows?

I'm using Arc 10.2.2. I have 2 files: "Input_Table.exe" (only 3 columns: "ID", "Lat", and "Lon") "Target_Shapefile.shp" (many columns including the same "ID", "Lat", and "Lon") Any rows in the ...
user avatar
  • 1,187
2 votes
4 answers
3k views

Creating queries to select by attribute with arcpy

I'm quite new with arcpy and I'm finding selecting by attribute a bit of a nightmare. There's a problem with my query on the script below [query = "\'Location\' = observer"], but I can't tell what it ...
user avatar
2 votes
2 answers
238 views

Generate sql WHERE clause from selected features

In ArcGIS Desktop, I can use various tools to interactively select features. These selection tools are handy for making complex selections (tabular or spatial) that would be otherwise cumbersome to ...
user avatar
  • 716
1 vote
1 answer
2k views

Select by attribute using modulo operation?

In ArcMap 10.5, I want to select the rows where the modulus of the objectid by 3 equals 1. How to write a SQL sentence in select by attribute window? My current query statement is something like ...
user avatar
0 votes
2 answers
857 views

Selecting table records by attribute if in Python list

I would like to create a subset of a table based on values in a Python list that I created from a search cursor. I have not been able to get the where_clause correct and keep getting errors. Here is ...
user avatar
  • 986
1 vote
1 answer
1k views

What is None argument in sql clause in UpdateCursor?

I have a bit of code that is a groupby iterator. It works well, and I understand most of it, but I am wondering what the None argument does within the sql_clause in the code below. I know this is ...
user avatar
  • 986
2 votes
1 answer
473 views

Using a variable inside a where clause

I am trying to loop through a list of states, and use each state as a variable within a where clause to select by attribute. Below is the code I am trying to run. Note: I will eventually be running ...
user avatar
  • 93
1 vote
0 answers
150 views

Where Clause for PgAdmin PostGIS

I'm trying to select streams that are a certain distance away from cities. I have been able to do it for a few, but I would like to do it to the entire column that contains the cities name without ...
user avatar
0 votes
0 answers
33 views

Using where clause for arcgis analysis in ArcPy? [duplicate]

I am trying to write a python code for select analysis. FIPS: column in feature nameofinputfeature whose values needs to be compared with OFIPS OFIPS: variable whose value is known each time the ...
user avatar
  • 755
2 votes
1 answer
1k views

Using UpdateCursor and Where Clause to manipulate attributes?

I am working on a practice problem, and i have hit a wall. Here is what the question is asking. Write a script that updates the attribute of SIZE with the values ‘Large’ or ‘Small’, depending on ...
user avatar
0 votes
1 answer
951 views

Using list of numbers to Select By Attribute in ArcPy?

I am trying to use Python to select all records whose attribute (which is a number) in a certain field is within a list. I cannot get the syntax correct. my list is: upstream = [9841978, 9842008, ...
user avatar
  • 986
1 vote
2 answers
308 views

Variable in where clause arcpy.Select

I'm trying to set up a loop that includes using items in the array along with string text to populate the where clause. I'm getting the invalid sql expression for the clause. Here's what I have so ...
user avatar
  • 153
2 votes
1 answer
8k views

How to address the alias of a sub-query in the where-clause in PostgreSQL/PostGIS?

I have a problem with a Postgres query and can't find a solution in stackexchange or any SQL Documentation. I have two tables in PostGIS, one for streets and one for house-numbers. I now want to find ...
user avatar
-1 votes
1 answer
59 views

Passing where clause with range that will prompt user in arcpy.select_analysis?

I am trying to query the user to enter a price range so that all those which are in his range will be retrieved. choice = input("Enter the budget range:") arcpy.Select_analysis("Zillow_Project.shp", "...
user avatar
4 votes
2 answers
1k views

Create table from results of ST_Intersection queries in PostGIS

I create a query in PostGIS using 'where' clause, and with that a table. now I want to use those attributes to create a intersection with other table... but I don't know how to call the attributes, ...
user avatar
2 votes
1 answer
128 views

Using a Variable in arcpy.SelectLayerByAttribute

I know this is a very basic problem I should be able to solve myself, but I've had no luck. I have a variable I want to use in the query for arcpy.SelectLayerByAttribute, but the line that was working ...
user avatar
1 vote
1 answer
268 views

Using where clause with FeatureClassToFeatureClass?

I want to split the shapefile with a field called FULLNAME and save those records with same FULLNAME to a new shapefile, which is the split by attribute. The following code has an error for the last ...
user avatar
1 vote
1 answer
313 views

Writing where clause for Feature Class To Feature Class in ArcPy?

The following picture shows the table for the shapefile. I need to extract those rows with different values of TotalCT, which means I need to extract the first row into a new shapefile named Value_1....
user avatar
1 vote
1 answer
547 views

Passing where clause as variable to arcpy.SearchCursor() gives ERROR 999999?

I'm having trouble passing my where clause for arcpy.SearchCursor as a variable. The following code successfully generates a query for me: PolyList = "C:\\Users\\korora912\\Desktop\\polygons.shp" ...
user avatar