DB_Table.write
writepathformaton_existing_filematch_columnson_problems
Group: Output
Aliases: export, output, save, to_file
Documentation
This function writes the table into a file. The specific behavior of the various File_Formats is specified below.
Arguments
path: The path to the output file.format: The format of the file. IfAuto_Detectis specified; the provided file determines the specific type and configures it appropriately. Details of this type are below.on_existing_file: Specified how to handle if the file already exists.match_columns: Specifies how to match columns against an existing file. IfMatch_Columns.By_Name- the columns are mapped by name against an existing file. If there is a mismatch, then aColumn_Name_Mismatcherror is raised. IfMatch_Columns.By_Position- the columns are mapped by position against an existing file. If there is a mismatch, then aColumn_Count_Mismatcherror is raised.on_problems: Specifies how to handle if a problem occurs, raising as a warning by default. The specific issues depend on theFile_Formatargument.
Returns
- If an unsupported
File_Formatis specified, anIllegal_Argumentis raised. - If the path to the parent location cannot be found or the filename is invalid, aFile_Error.Not_Foundis raised. - If another IO error occurs, such as access denied, anFile_Error.IO_Erroris raised. - If appending and the columns do not match, aColumn_Count_Mismatchis raised. - Other specific errors or warnings that can be raised depend on the format argument. - Otherwise, the file is loaded following the rules of the format parameter.
Examples
Write a database table to a CSV file.
import Standard.Examples
from Standard.Database import all
example_to_csv =
connection = Database.connect (SQLite.From_File (File.new "db.sqlite"))
table = connection.query (SQL_Query.Table_Name "Table")
table.write (enso_project.data / "example_csv_output.csv")
Remarks
File_Format write behaviors
Auto_Detect: The file format is determined by the provided file.BytesandPlain_Text: The Table does not support these types in thewritefunction. If passed as format, anIllegal_Argumentis raised. To write out the table as plain text, the user needs to call theText.from Tablemethod and then use theText.writefunction.