.\" 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" "May 06, 2025" "" "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, \-\-input Input vector datasets [required] \-o, \-\-output Output vector dataset [required] \-\-sql |@ SQL statement(s) [may be repeated] [required] Common Options: \-h, \-\-help Display help message and exit \-\-json\-usage Display usage as JSON document and exit \-\-config = Configuration option [may be repeated] \-\-progress Display progress bar Options: \-f, \-\-of, \-\-format, \-\-output\-format Output format (\(dqGDALG\(dq allowed) \-\-co, \-\-creation\-option = Creation option [may be repeated] \-\-lco, \-\-layer\-creation\-option = Layer creation option [may be repeated] \-\-overwrite Whether overwriting existing output is allowed \-\-update Whether to open existing dataset in update mode \-\-overwrite\-layer Whether overwriting existing layer is allowed \-\-append Whether appending to existing layer is allowed \-\-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] \-\-oo, \-\-open\-option = Open options [may be repeated] .EE .UNINDENT .UNINDENT .SH DESCRIPTION .sp \fBgdal vector sql\fP returns one or several layers evaluated from SQL statements. .SS Standard options .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 \-\-co = 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 \-lco = Layer creation option (format specific) .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 \-\-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. What SQL dialects a driver supports can be checked with \(dqgdal vector info\(dq. .sp Supported dialects can be checked with \fBgdal vector info\fP\&. For example: .INDENT 7.0 .INDENT 3.5 .sp .EX $ gdal vector info \-\-format \(dqPostgreSQL\(dq Supported SQL dialects: NATIVE OGRSQL SQLITE $ gdal vector info \-\-format \(dqESRI Shapefile\(dq Supported SQL dialects: OGRSQL SQLITE .EE .UNINDENT .UNINDENT .UNINDENT .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 .SS Advanced options .INDENT 0.0 .TP .B \-\-oo = Dataset open option (format specific). .sp May be repeated. .UNINDENT .INDENT 0.0 .TP .B \-\-if 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 .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 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 .SH AUTHOR Even Rouault .SH COPYRIGHT 1998-2025 .\" Generated by docutils manpage writer. .