table insert (missing) columns

Prev Next

Function Names

table insert columns, table insert missing columns

Description

This function inserts one or more columns into the table with initial values.
table insert missing columns will only insert and initialize columns if they are missing. If they exist, then they will not be touched or the contents being initialized.

Call as: procedure or function

Restrictions

Indirect parameter passing is disabled

Parameter count

2 -4

Parameters

No.TypeDescription
1.
input
string Name of existing table

2
input
table columns Header names columns to add

See table columns as function parameters for general ruling for this parameter.
Specific rules apply for this function:

  • Any number of header names may be specified. Column numbers are not allowed here.

Opt. 3
input
set or string Initial Values

If this set contains more values than in 2nd argument, then the excess values will be discarded. If this set contains less values, then the first value will be referred after the last one (modulo pattern). If the parameter is blank, or missing, then the columns will be initialized with blanks.

opt. 4
input
table column Destination column

See table columns as function parameters for general ruling for this parameter.
Specific rules apply for this function:

  • Specify only one header name and column number

The new column will be inserted to the left. To insert them to the right, using shifted Table Column Specifications is a possible option, or use column numbers. Negative indexing is supported, where -1 adds the new column after (and not before) the last column.

Return value

TypeDescription
numeral Number of headers inserted

-1 is returned if no header row has been found

Exceptions

Table not found

Examples

       table initialize( t,
               { { First Name, Last Name, Given Name, Birth Year },
                 { Abel,       Adams,     A.,         1990 },
                 { Betty,      Beavers,   B.,         1995 },
                 { Charlie,    Collins,   C.,         2000 },
                 { Daniela,    Douglas,   D.,         2005 } } );

       table insert columns( t, Gender, "M or F", First Name );
       table insert columns( t, Phone, {"1-202...", "1-212..."}, '>First Name' );
       table insert columns( t, Birthplace, "-", -1 );

       count[] = table insert missing columns( t, {Birthplace, Street} );
       echo(count[]); // Inserted 1 additional column.

       table list ( t );

Output

1
    0 : Gender | First Name | Phone    | Last Name | Given Name | Birth Year | Birthplace | Street
    1 : M or F | Abel       | 1-202... | Adams     | A.         | 1990       | -          |       
    2 : M or F | Betty      | 1-202... | Beavers   | B.         | 1995       | -          |       
    3 : M or F | Charlie    | 1-202... | Collins   | C.         | 2000       | -          |       
    4 : M or F | Daniela    | 1-202... | Douglas   | D.         | 2005       | -          |       

Try it yourself: Open LIB_Function_table_insert_columns.b4p in B4P_Examples.zip. Decompress before use.

See also

table delete columns
table copy columns