1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
.\" 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 "SQL2CSV" "1" "Aug 16, 2024" "2.2.0" "csvkit"
.SH NAME
sql2csv \- sql2csv Documentation
.SH DESCRIPTION
.sp
Executes arbitrary commands against a SQL database and outputs the results as a CSV:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
usage: sql2csv [\-h] [\-v] [\-l] [\-V] [\-\-db CONNECTION_STRING] [\-\-query QUERY]
[\-e ENCODING] [\-H]
[FILE]
Execute a SQL query on a database and output the result to a CSV file.
positional arguments:
FILE The file to use as the SQL query. If FILE and \-\-query
are omitted, the query is piped data via STDIN.
optional arguments:
\-h, \-\-help show this help message and exit
\-\-db CONNECTION_STRING
A SQLAlchemy connection string to connect to a
database.
\-\-engine\-option ENGINE_OPTION ENGINE_OPTION
A keyword argument to SQLAlchemy\(aqs create_engine(), as
a space\-separated pair. This option can be specified
multiple times. For example: thick_mode True
\-\-execution\-option EXECUTION_OPTION EXECUTION_OPTION
A keyword argument to SQLAlchemy\(aqs
execution_options(), as a space\-separated pair. This
option can be specified multiple times. For example:
stream_results True
\-\-query QUERY The SQL query to execute. Overrides FILE and STDIN.
\-e ENCODING, \-\-encoding ENCODING
Specify the encoding of the input query file.
\-H, \-\-no\-header\-row Do not output column names.
.ft P
.fi
.UNINDENT
.UNINDENT
.SH EXAMPLES
.sp
Load sample data into a table using \fI\%csvsql\fP and then query it using \fIsql2csv\fP:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
csvsql \-\-db \(dqsqlite:///dummy.db\(dq \-\-tables \(dqtest\(dq \-\-insert examples/dummy.csv
sql2csv \-\-db \(dqsqlite:///dummy.db\(dq \-\-query \(dqselect * from test\(dq
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
Load data about financial aid recipients into PostgreSQL. Then find the three states that received the most, while also filtering out empty rows:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
createdb recipients
csvsql \-\-db \(dqpostgresql:///recipients\(dq \-\-tables \(dqfy09\(dq \-\-insert examples/realdata/FY09_EDU_Recipients_by_State.csv
sql2csv \-\-db \(dqpostgresql:///recipients\(dq \-\-query \(dqselect * from fy09 where \e\(dqState Name\e\(dq != \(aq\(aq order by fy09.\e\(dqTOTAL\e\(dq limit 3\(dq
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
You can even use it as a simple SQL calculator (in this example an in\-memory SQLite database is used as the default):
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
sql2csv \-\-query \(dqselect 300 * 47 % 14 * 27 + 7000\(dq
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
The connection string \fI\%accepts parameters\fP\&. For example, to set the encoding of a MySQL database:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
sql2csv \-\-db \(aqmysql://user:pass@host/database?charset=utf8\(aq \-\-query \(dqSELECT myfield FROM mytable\(dq
.ft P
.fi
.UNINDENT
.UNINDENT
.SH AUTHOR
Christopher Groskopf and contributors
.SH COPYRIGHT
2016, Christopher Groskopf and James McKinney
.\" Generated by docutils manpage writer.
.
|