pub struct Settings {
pub format: Format,
pub header: bool,
pub separator: String,
pub newline: String,
pub nullvalue: String,
pub table: String,
}Expand description
Everything about how output is printed, which is what the dot commands change.
Fields§
§format: FormatThe output mode.
header: boolWhether to print the column names.
separator: StringWhat goes between two values in the separated modes.
newline: StringWhat goes between two rows in the separated modes.
nullvalue: StringWhat a null prints as in the modes that do not have a spelling of their own for it.
table: StringThe table name .mode insert puts in the statements it writes.
Implementations§
Source§impl Settings
impl Settings
Sourcepub fn set_format(&mut self, format: Format)
pub fn set_format(&mut self, format: Format)
Switches mode, resetting both separators to that mode’s defaults.
Resetting is DuckDB’s behaviour and it surprises people, so it is worth saying why it is
right: .mode csv means “write me a CSV”, and a pipe separator left over from an earlier
.mode list would produce a file that is not one. The header setting is deliberately left
alone, which is also DuckDB’s behaviour and was checked against the binary rather than
guessed, because .headers off is a thing somebody says once and expects to stay said.
Sourcepub fn set_format_flag(&mut self, format: Format)
pub fn set_format_flag(&mut self, format: Format)
Switches mode the way a command line flag does, which is not the way .mode does.
There is no rule here, only a table, and the table is upstream’s. -ascii sets both
separators, -csv sets the column separator and leaves the row separator, and the other ten
flags set neither. That is three behaviours across three flags on one build, which is why
this is a match rather than a line of code.
It matters because these are the modes people pipe into other programs. duckdb -csv ends a
row with \n and duckdb -cmd ".mode csv" ends it with \r\n, and duckdb -quote writes
'a'|'b' where duckdb -cmd ".mode quote" writes 'a','b'. A script written against the
flag is a script whose next stage counts bytes or splits on a character, so copying the
oversight is the whole point.
Read out of .show on duckdb v2.0.0-dev84237 for all twelve flags, once on its own and
once after -separator ';' -newline '@' so that leaving a separator alone can be told apart
from setting it to the same thing it already was. Per #239.