alter()

Read(1490) Label: table sequence, alter, field,

Here’s how to use alter() functions.

T.alter(Fi,…;F’i,…)

Description:

The function alters fields in a table sequence.

Syntax:

T.alter(Fi,…;F’i,…)

Note:

The function modifies fields of table sequence T according to the specified order Fi,…, and arranges the other fields in their original order. Add parameter Fi as a new field if there isn’t such a field in the table sequence; parameter F’I is the field to be deleted.

Parameter:

T

A table sequence

Fi

Field name

F’i

Field name

Return value:

A table sequence

Example:

 

A

 

1

=demo.query("select class,studentid,subject,score from scores")

The scores table contains columns as follows:

2

=A1.alter(classname;CLASS)

Add a new field classname to A1’s table sequence and deletes CLASS field.

3

=A2.alter(classname,STUDENTID,gender)

Add a new field gender to A2’s table sequence according to the specied position and arrange the rest of the fields after the specific ones in their original order.

4

=A3.alter(;gender,classname)

Delete gender field and classname field.

T.alter( F:x,…;F’,… )

Description:

Alter one or more fields in an entity table.

Syntax:

T.alter(F:x,…;F’,…)

Note:

The function, supported only when a table is of columnar storage, adds a field F to entity table/multizone entity table T and deletes an old field F’. Values of the new field are obtained by calculating expression x and populated to the table. The dimension and sorting field before it must not be modified.

Parameter:

T

An entity table/multizone entity table

F

Name of the to-be-added field

x

An expression

F’

An existing field

Return value:

An entity table/multizone entity table

Example:

 

A

 

1

=file("emp.ctx")

An existing composite table file.

2

=A1.open()

Open the composite table’s base table.

3

=A2.cursor().fetch()

Query data in the base table.

4

=A2.alter(NEW_Salary:SALARY+1000;GENDER)

Add NEW_Salary field to the base table through calculating expression SALARY+1000, and delete existing field GENDER.

5

=A2.cursor().fetch()

Check the base table and we can see that the new field is added and GENDER field is deleted.