create()

Read(540) Label: create,

Here’s how to use creat() function.

create ()

Description:

Create an empty table sequence.

Syntax:

create(Fi,…)

Note:

The function creates an empty table sequence taking Fi,… as its fields.

Parameters:

Fi

Field name

Return value:

An empty table sequence

Example:

 

A

 

1

=create(id,name,sex)

create(# Fi ,…)

Description:

Create an empty table sequence with one or more keys set.

Syntax:

create(#Fi,…) 

Note:

The function creates an empty table sequence that has the fields Fi,…. A field name headed by the sign # is a key.

Parameters:

Fi

Field name

Return value:

Empty table sequence

Example:

 

A

 

1

=create(#id,#name,gender)

id field and name field are keys

f.create( C ,…; x )

Description:

Create a composite table from a corresponding file.

Syntax:

f.create(C,…;x)

Note:

The function creates a composite table using composite table file f, and generates a multi-zone composite table if f is a file group. Parameter C is a column, which is a dimension if it is preceded by #, of the would-be composite table, and parameter x is a zone table expression. The dimension and all fields before it must be ordered.

Parameters:

f

A composite table file or a file group

C

A column of the would-be composite table

x

A zone table expression

Options:

@u

Do not compress the file; default is to compress it

@r

Generate a rowwise file while default is columnar storage, which does not support the multicursor

@y

Force to re-create the file even if the target file already exists; defalut is to terminate computation and report error

@p

egment by the first field

Return value:

A composite table or a file group

Example:

 

A

 

1

=file("employee1.ctx")

Generate composite table file employee1.ctx

2

=A1.create(#EID,NAME,GENDER)

Create A1’s base table whose columns are EID, NAME and GENDER; EID is the dimension

3

=connect("demo").cursor("select EID,NAME,GENDER,SALARY  from employee where GENDER='M' order by SALARY")

 

4

=connect("demo").cursor("select EID,NAME,GENDER,SALARY  from employee where GENDER='F' order by SALARY")

 

5

=[A3,A4].mcursor()

Return a multicursor

6

=file("emp.ctx":[1,2])

Generate a file group, which contains two files 1.emp.ctx and 2.emp.ctx

7

=A6.create@y(#EID,NAME,GENDER,SALARY;if(GENDER=="F",1,2))

Create a multi-zone composite table; if(GENDER=="F",1,2) is zone table expression and @y forces to re-create the target file even if it already exists

8

=A7.append@i(A5)

Append data in A5’s multicursor to A7’s multi-zone composite table; each part of the multicursor uniquely corresponds to A7’s one zone table

9

=file("1.emp.ctx").open().cursor().fetch()

View data in zone table 1.emp.ctx

10

=file("2.emp.ctx").open().cursor().fetch()

View data in zone table 2.emp.ctx

P.create()

Description:

Generate a new empty table sequence by copying data structure of a specific record sequence.

Syntax:

P.create()

Note:

If parameter P has the key, just copy it.

Parameters:

P

A record sequence

Return value:

A new empty table sequence

Example:

Ø  Generated from a record sequence

 

A

 

1

=demo.query("select top 1 * from DEPARTMENT")

2

=A1.to()

Generate a record sequence

3

=A2.create()

Create an empty table sequence that has same data structure as A2’s

 

Ø  When there is the key

 

A

 

1

=demo.query("select top 1 * from DEPARTMENT ")

2

=A1.keys(DEPT)

 

3

=A1.to()

Generate a record sequence

4

=A3.create()

Create an empty table sequence that has same data structure as A3’s while copying the key

T .create ()

Description:

Create an empty table sequence by duplicating data structure of a specific table sequence.

Syntax:

T.create()

Note:

If table sequence T has a key, then duplicate the key at the same time.

Parameters:

T

A table sequence

Return value:

A new empty table sequence

Example:

Ø  Created from a normal table sequence

 

A

 

1

=demo.query("select top 1 * from DEPARTMENT")

2

=A1.create()

 

Create an empty table of same structure as A1

 

Ø  Copy the key

 

A

 

1

=demo.query("select * from DEPARTMENT ")

2

=A1.keys(DEPT)

 

3

=A1.create()

Create an empty table sequence that has not only the same data structure, but also the same key, as table sequence A1

T.create( f;x )

Description:

  Create a new composite table file using the data structure of an existing composite table.

Syntax:

  T.create(f;x)

Note:

  The function creates a new composite table file f using table structure of composite table T, and generates a multi-zone composite table file when the target f is a file group. f will include T’s attached tables.

Parameters:

T

A composite table

f

A composite table file or a file group

x

An integer, which is the zone table expression

Return value:

  A composite table

Example:

 

A

 

1

=create(k1,v1).record([1,10,2,20]).cursor()

Return a cursor that has data as follows:

2

=create(k1,k2,v2).record([1,11,111,2,22,222]).cursor()

Return a cursor that has data as follows:

3

=file("ctb.ctx").open()

Open a composite table file that contains an attached table table2

4

=A3.create@y(file("emp929.ctx"))

Create new composite table file ctbCp.ctx, as well as its attached table, using data structure of composite table ctb.ctx

5

=A4.append@i(A1)

Append data of A1’s cursor to the base table of composite table ctbCp.ctx

6

=A4.attach(table2)

Open A4’s attached table table2

7

=A6.append@i(A2)

Append data of A2’s cursor to ctbCp.ctx’s attached table table2

r .create()

Description:

Create a table sequence by copying the data structure of a specified record.

Syntax:

r.create()

Note:

If there’s a key defined in record r, then copy the key at the same time.

Parameters:

r

A record

Return value:

A new empty table sequence

Example:

Ø  Generate an empty table sequence from an average record

 

A

 

1

=demo.query("select top 1 * from DEPARTMENT")

2

=A1(1).create()

 

Create an empty table of same structure as A1(1)

 

Ø  Generate an empty table sequence from a record with the key

 

A

 

1

=demo.query("select * from DEPARTMENT ")

2

=A1.keys(DEPT)

 

3

=A1(1).create()

Generate an empty table sequence by copying the data structure of the record A1(1) and the key