Skip to main content

DB_Table.write

writepathformaton_existing_filematch_columnson_problems

Group: Output

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. If Auto_Detect is 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. If Match_Columns.By_Name - the columns are mapped by name against an existing file. If there is a mismatch, then a Column_Name_Mismatch error is raised. If Match_Columns.By_Position - the columns are mapped by position against an existing file. If there is a mismatch, then a Column_Count_Mismatch error is raised.
  • on_problems: Specifies how to handle if a problem occurs, raising as a warning by default. The specific issues depend on the File_Format argument.

Returns

  • If an unsupported File_Format is specified, an Illegal_Argument is raised. - If the path to the parent location cannot be found or the filename is invalid, a File_Error.Not_Found is raised. - If another IO error occurs, such as access denied, an File_Error.IO_Error is raised. - If appending and the columns do not match, a Column_Count_Mismatch is 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.
  • Bytes and Plain_Text: The Table does not support these types in the write function. If passed as format, an Illegal_Argument is raised. To write out the table as plain text, the user needs to call the Text.from Table method and then use the Text.write function.