Description:
Write a sequence/table sequence/record sequence into a file.
Syntax:
f.export( A, x:F,…;s)
Note:
The function writes sequence/table sequence/record sequence A into file f in the form of text; it will auto-create an f, which is in the text format by default, if the file doesn’t exist (but the path can’t be auto-created). If A contains a serial byte field, the serial byte values will be written as in the form of integers.
If A is a table sequence or a record sequence, write all fields into the file if parameter x is absent. If the values of a to-be-exported field are referenced records, just write their primary key values into f. The unexportable fields in A can’t be written into f. A one-field file without field name will be generated if A is a sequence and parameter x is absent.
Parameters:
f |
A file |
A |
The record sequence/sequence to be exported |
x |
The field to be exported. If omitted, all the fields of A that can be textualized will be exported. The sign # is used to represent a field with a sequence number |
F |
Resulting field name. If omitted, then use the original field name |
s |
The user-defined separator used in the text file, and the default separator is tab |
Options:
@t |
Export field description, or the headers, as the first row of the file |
@a |
Append. The appended records and the original records should be of the same structure, otherwise error will be reported. Ignore @t option if the there is data in the original file; overwrite the original file by default |
@b |
Convert into binary file to speed up the processing; does not support parameter s. |
@c |
Use comma as the separator when parameter s is absent, but the user-defined separator s should take priority when the parameter is present |
@z |
Force the execution of @b and write the sequence to the binary file f in segment by segment. The sequence won’t be segmented by default. In this option, parameter s, when present, is a grouping expression by which A is ordered; perform data segmentation only when s is changed. This option is often used to export a large amount of data to a binary file in segments with parallel processing and it can make sure that each segment will be wholly exported |
@w |
Use Windows-style \r\n line break; by default the line break is specified by the operating system |
@q |
Enclose the exported text field values and headers with quotation marks |
@o |
Use quotation marks as the escape character; need to work with @q. Without it the escape character is the Java-style slash (\) |
Example:
Write a record sequence into a txt file.
|
A |
|
|
|||
1 |
=demo.query(select * from DEPARTMENT) |
|
|
|||
2 |
=file(D:\\Department.txt).export(A1) |
|
|
|||
3 |
=file(D:\\Department.txt).export@t(A1) |
Use @t to export field headers the first record as the title |
|
|||
f4 |
=file(D:\\Department2.txt).export(A1; |) |
|
|
|||
5 |
=file(D:\\Department2.txt).export(A1;) |
|
|
|||
6 |
=file(D:\\Department2.txt).export@a(A1) |
Still the above example, append the contents from A1 to the contents of the file |
|
|||
7 |
=file(D:\\Department3.txt).export@b(A1) |
Export the file content in binary format |
|
|||
8 |
=file(D:\\Department4.txt).export@t(A1,DEPT:Dept1;"|") |
If not omitting x, then only export the specified field |
|
|||
9 |
=file("D:\\dept1.txt").export@ta(A1) |
Since dept1.txt does not exist, create it after the execution begins and then import the first row as the title |
|
|||
10 |
[a,s,d,f] |
|
|
|||
11 |
=file("D:\\myfile.txt").export(A10) |
myfile.txt is a one-field file without a field name |
|
|||
12 |
=file("D:\\Department6.txt").export@c(A1) |
|
|
|||
13 |
=demo.query("select * from EMPLOYEE order by GENDER") |
Sort by GENDER |
|
|||
14 |
=file("D:\\EMPLOYEE.btx").export@z(A12,EID,NAME,SURNAME,GENDER,SALARY;GENDER) |
Group the file by GENDER and export it to EMPLOYEE.btx |
|
|||
15 |
=file("D:\\EMPLOYEE.txt").export@w(A1) |
Use Windows-style \r\n line break |
||||
16 |
=demo.query("select * from DEPARTMENT").keys(MANAGER) |
|
||||
17 |
=A13.switch(DEPT,A15:DEPT) |
|
||||
18 |
=file("D:\\EMPLOYEE1.txt").export@t(A16) |
Values of DEPT field in A16 are referenced records; in this case the primary key of the table sequence need to be exported |
||||
19 |
=demo.query("select * from DEPARTMENT") |
|
||||
20 |
=file("D:\\Department7.txt").export(A19,#1) |
#1 represents the first column, so only that column of data is exported |
||||
21 |
=file("D:\\Dep1.txt").export@q(A19,#1) |
|
||||
22 |
=["12\r34","aa\nbb"] |
|
||||
23 |
=file("D:\\T1.txt").export@q(A22) |
|
||||
24 |
=file("D:\\T2.txt").export@qo(A22) |
|
||||
Note:
Format of text file: Separate records by carriage return, and fields by the user-defined separator. The default separator is tab. Here records of table sequence/record sequence/sequence A must be of the same data structure.
Related functions: