write
write, keyword
Writes table data to a file in the account filesystem.
Example
table Products = with
[| as Product, as Color, as Price |]
[| "shirt", "white", 10.50 |]
[| "pants", "blue", 15.00 |]
[| "hat", "red", 5.25 |]
write Products as "/sample/products.csv" with
Product = Products.Product
Color = Products.Color
Price = Products.Price
show table "Products" with
Products.Product
Products.Color
Products.Price
This outputs the following table:
| Product | Color | Price |
|---|---|---|
| shirt | white | 10.5 |
| pants | blue | 15 |
| hat | red | 5.25 |
Remarks
File format is inferred from the extension (.csv, .tsv, .xlsx, .ion).
Unknown extensions produce a runtime error.
Only .ion supports ranvar, zedfunc, and embedding values.
Written columns must be scalar values, not tuples. File output also rejects
types that are not supported by the target file formats, such as markdown.
Writes are atomic and become visible only after the script completes.
The write statement can be placed inside an if / else branch to perform
conditional exports; see the if keyword.
The order by clause is supported to control the row order of the exported file.
When a schema declares an enum column, the source vector must already be of
the same enum type; use enum<<X>> to convert from text. Mismatched enum types
are rejected.
table enum Color = "white", "grey", "blue", "red"
schema '/sample/products.ion' with
Product : text
Color : enum Color
Price : number
table Products = with
[| as Product, as Color, as Price |]
[| "shirt", "white", 10.50 |]
[| "pants", "blue", 15.00 |]
[| "hat", "red", 5.25 |]
Products.Color = enum<<Color>>(Products.Color)
write Products as '/sample/products.ion'
Metadata comments
Files produced by write can carry documentation comments using ///. These comments are surfaced in the Envision editor when inspecting downstream variables that originate from the file.
table Products = with
[| as Product, as Units |]
[| "shirt", 10 |]
[| "pants", 15 |]
/// Products export
write Products as "/sample/products.tsv" with
/// Product identifier
Product = Products.Product
/// Units sold
Units = Products.Units