.\" Man page generated from reStructuredText. . . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .TH "GDAL-VECTOR-SQL" "1" "Aug 18, 2026" "" "GDAL" .SH NAME gdal-vector-sql \- Apply SQL statement(s) to a dataset .sp Added in version 3.11. .SH SYNOPSIS .INDENT 0.0 .INDENT 3.5 .sp .EX Usage: gdal vector sql [OPTIONS] [] Apply SQL statement(s) to a dataset. Positional arguments: \-i, \-\-dataset, \-\-input Input vector datasets [required] [not available in pipelines] \-o, \-\-output Output vector dataset [not available in pipelines] Common Options: \-h, \-\-help Display help message and exit \-\-json\-usage Display usage as JSON document and exit \-\-config = Configuration option [may be repeated] \-q, \-\-quiet Quiet mode (no progress bar or warning message) [not available in pipelines] Options: \-f, \-\-of, \-\-format, \-\-output\-format Output format (\(dqGDALG\(dq allowed) [not available in pipelines] \-\-co, \-\-creation\-option = Creation option [may be repeated] [not available in pipelines] \-\-lco, \-\-layer\-creation\-option = Layer creation option [may be repeated] [not available in pipelines] \-\-overwrite Whether overwriting existing output dataset is allowed [not available in pipelines] \-\-update Whether to open existing dataset in update mode [not available in pipelines] \-\-overwrite\-layer Whether overwriting existing output layer is allowed [not available in pipelines] \-\-append Whether appending to existing layer is allowed [not available in pipelines] Mutually exclusive with \-\-upsert \-\-skip\-errors Skip errors when writing features [not available in pipelines] \-\-sql |@ SQL statement(s) [may be repeated] [required] \-\-output\-layer Output layer name(s) [may be repeated] \-\-dialect SQL dialect (e.g. OGRSQL, SQLITE) Advanced Options: \-\-if, \-\-input\-format Input formats [may be repeated] [not available in pipelines] \-\-oo, \-\-open\-option = Open options [may be repeated] [not available in pipelines] \-\-output\-oo, \-\-output\-open\-option = Output open options [may be repeated] [not available in pipelines] \-\-upsert Upsert features (implies \(aqappend\(aq) [not available in pipelines] Mutually exclusive with \-\-append .EE .UNINDENT .UNINDENT .SH DESCRIPTION .sp \fBgdal vector sql\fP returns one or several layers evaluated from SQL statements. .sp Starting with GDAL 3.12, when using \fI\%\-\-update\fP, and without an output dataset specified, this can be used to execute statements that modify the input dataset, such as UPDATE, DELETE, etc. .SH GDALG OUTPUT (ON-THE-FLY / STREAMED DATASET) .sp This program supports serializing the command line as a JSON file using the \fBGDALG\fP output format. The resulting file can then be opened as a vector dataset using the \fI\%GDALG: GDAL Streamed Algorithm\fP driver, and apply the specified pipeline in a on\-the\-fly / streamed way. .SH PROGRAM-SPECIFIC OPTIONS .INDENT 0.0 .TP .B \-\-output\-layer Output SQL layer name(s). If not specified, a generic layer name such as \(dqSELECT\(dq may be generated. .sp Must be specified as many times as there are SQL statements, either as several \-\-output\-layer arguments, or a single one with the layer names combined with comma. .UNINDENT .INDENT 0.0 .TP .B \-\-quiet Added in version 3.12. .sp Silence potential information messages. .UNINDENT .INDENT 0.0 .TP .B \-\-sql |@ SQL statement to execute that returns a table/layer (typically a SELECT statement). .sp Can be repeated to generated multiple output layers (repeating \-\-sql for each output layer) .UNINDENT .INDENT 0.0 .TP .B \-\-dialect SQL dialect. .sp By default the native SQL of an RDBMS is used when using \fBgdal vector sql\fP\&. If using \fBsql\fP as a step of \fBgdal vector pipeline\fP, this is only true if the step preceding \fBsql\fP is \fBread\fP, otherwise the \fI\%OGRSQL\fP dialect is used. .sp If a datasource does not support SQL natively, the default is to use the \fBOGRSQL\fP dialect, which can also be specified with any data source. .sp The \fI\%SQL SQLite dialect\fP dialect can be chosen with the \fBSQLITE\fP and \fBINDIRECT_SQLITE\fP dialect values, and this can be used with any data source. Overriding the default dialect may be beneficial because the capabilities of the SQL dialects vary. .sp Supported dialects can be checked with \fBgdal \-\-format\fP\&. For example: .INDENT 7.0 .INDENT 3.5 .sp .EX $ gdal \-\-format \(dqPostgreSQL\(dq [...] Supported SQL dialects: NATIVE OGRSQL SQLITE [...] $ gdal \-\-format \(dqESRI Shapefile\(dq [...] Supported SQL dialects: OGRSQL SQLITE [...] .EE .UNINDENT .UNINDENT .UNINDENT .SH STANDARD OPTIONS .INDENT 0.0 .TP .B \-\-append Whether appending features to existing layer(s) is allowed. This also creates the output dataset if it does not exist yet. .UNINDENT .INDENT 0.0 .TP .B \-\-co, \-\-creation\-option = Many formats have one or more optional dataset creation options that can be used to control particulars about the file created. For instance, the GeoPackage driver supports creation options to control the version. .sp May be repeated. .sp The dataset creation options available vary by format driver, and some simple formats have no creation options at all. A list of options supported for a format can be listed with the \fI\%\-\-formats\fP command line option but the documentation for the format is the definitive source of information on driver creation options. See \fI\%Vector drivers\fP format specific documentation for legal creation options for each format. .sp Note that dataset creation options are different from layer creation options. .UNINDENT .INDENT 0.0 .TP .B \-\-if, \-\-input\-format Format/driver name to be attempted to open the input file(s). It is generally not necessary to specify it, but it can be used to skip automatic driver detection, when it fails to select the appropriate driver. This option can be repeated several times to specify several candidate drivers. Note that it does not force those drivers to open the dataset. In particular, some drivers have requirements on file extensions. .sp May be repeated. .UNINDENT .INDENT 0.0 .TP .B \-\-lco, \-\-layer\-creation\-option = Many formats have one or more optional layer creation options that can be used to control particulars about the layer created. For instance, the GeoPackage driver supports layer creation options to control the feature identifier or geometry column name, setting the identifier or description, etc. .sp May be repeated. .sp The layer creation options available vary by format driver, and some simple formats have no layer creation options at all. A list of options supported for a format can be listed with the \fI\%\-\-formats\fP command line option but the documentation for the format is the definitive source of information on driver creation options. See \fI\%Vector drivers\fP format specific documentation for legal creation options for each format. .sp Note that layer creation options are different from dataset creation options. .UNINDENT .INDENT 0.0 .TP .B \-\-oo, \-\-open\-option = Dataset open option (format specific). .sp May be repeated. .UNINDENT .INDENT 0.0 .TP .B \-f, \-\-of, \-\-format, \-\-output\-format Which output vector format to use. Allowed values may be given by \fBgdal \-\-formats | grep vector | grep rw | sort\fP .UNINDENT .INDENT 0.0 .TP .B \-\-output\-open\-option, \-\-output\-oo = Added in version 3.12. .sp Dataset open option for output dataset (format specific). .sp May be repeated. .UNINDENT .INDENT 0.0 .TP .B \-\-overwrite Allow program to overwrite existing target file or dataset. Otherwise, by default, \fBgdal\fP errors out if the target file or dataset already exists. .UNINDENT .INDENT 0.0 .TP .B \-\-overwrite\-layer Whether overwriting the existing output vector layer is allowed. .UNINDENT .INDENT 0.0 .TP .B \-\-skip\-errors Added in version 3.12. .sp Whether failures to write feature(s) should be ignored. Note that this option sets the size of the transaction unit to one feature at a time, which may cause severe slowdown when inserting into databases. .UNINDENT .INDENT 0.0 .TP .B \-\-update Whether to open an existing output dataset in update mode. .UNINDENT .INDENT 0.0 .TP .B \-\-upsert Added in version 3.12. .sp Variant of \fI\%\-\-append\fP where the \fI\%OGRLayer::UpsertFeature()\fP operation is used to insert or update features instead of appending with \fI\%OGRLayer::CreateFeature()\fP\&. .sp This is currently implemented only in a few drivers: \fI\%GPKG \-\- GeoPackage vector\fP, \fI\%Elasticsearch: Geographically Encoded Objects for Elasticsearch\fP and \fI\%MongoDBv3\fP (drivers that implement upsert expose the \fI\%GDAL_DCAP_UPSERT\fP capability). .sp The upsert operation uses the FID of the input feature, when it is set (and the FID column name is not the empty string), as the key to update existing features. It is crucial to make sure that the FID in the source and target layers are consistent. .sp For the GPKG driver, it is also possible to upsert features whose FID is unset or non\-significant (the \fB\-\-unset\-fid\fP option of \fI\%gdal vector edit\fP can be used to ignore the FID from the source feature), when there is a UNIQUE column that is not the integer primary key. .UNINDENT .INDENT 0.0 .TP .B \-q, \-\-quiet Suppress progress bar and some warning messages. .UNINDENT .SH RETURN STATUS CODE .sp The program returns status code 0 in case of success, and non\-zero in case of error (non\-blocking errors emitted as warnings are considered as a successful execution). .SH EXAMPLES .SS Example 1: Generate a GeoPackage file with a layer sorted by descending population .INDENT 0.0 .INDENT 3.5 .sp .EX $ gdal vector sql in.gpkg out.gpkg \-\-output\-layer country_sorted_by_pop \-\-sql=\(dqSELECT * FROM country ORDER BY pop DESC\(dq .EE .UNINDENT .UNINDENT .SS Example 2: Generate a GeoPackage file with 2 SQL result layers .INDENT 0.0 .INDENT 3.5 .sp .EX $ gdal vector sql in.gpkg out.gpkg \-\-output\-layer=beginning,end \-\-sql=\(dqSELECT * FROM my_layer LIMIT 100\(dq \-\-sql=\(dqSELECT * FROM my_layer OFFSET 100000 LIMIT 100\(dq .EE .UNINDENT .UNINDENT .SS Example 3: Modify in\-place a GeoPackage dataset .INDENT 0.0 .INDENT 3.5 .sp .EX $ gdal vector sql \-\-update my.gpkg \-\-sql \(dqDELETE FROM countries WHERE pop > 1e6\(dq .EE .UNINDENT .UNINDENT .SS Example 4: Add a new field to an existing layer of a GeoPackage .INDENT 0.0 .INDENT 3.5 .sp .EX $ gdal vector sql \-\-update my.gpkg \-\-sql \(dqALTER TABLE countries ADD COLUMN abbrev STRING(10)\(dq .EE .UNINDENT .UNINDENT .SS Example 5: Append to an existing layer of a GeoPackage file .INDENT 0.0 .INDENT 3.5 .sp .EX $ gdal vector pipeline read europe.gpkg ! \e sql \-\-sql \(dqSELECT * FROM country WHERE pop > 1e6\(dq ! \e write \-\-append \-\-output\-layer\-name=world world.gpkg .EE .UNINDENT .UNINDENT .SH AUTHOR Even Rouault .SH COPYRIGHT 1998-2026 .\" Generated by docutils manpage writer. .