The
seq_filter()function has as first argument a boolean type, and the return sequence is of the type of the second argument. The result sequence contains only those elements of sequence 2 for which the corresponding element of sequence 1 is true. Theseq_filter_pos()function returns the positions of the elements that aretruein the input sequence.Following is an example script demonstrating the these functions:
INSERT INTO SimpleSequence(testNumber,bVal1,iVal1) VALUES(1,'{0,1,0,1}','{42,-13,27,19}'); SELECT bVal1, iVal1, seq_filter(bVal1,iVal1) AS "filter", bVal1, seq_filter_pos(bVal1) AS "filter_pos" FROM SimpleSequence WHERE testNumber = 1; bVal1{} iVal1{} filter{} ------------------------------------------------- {0, 1, 0, 1} {42, -13, 27, 19} {-13, 19} bVal1{} filter_pos{} ------------------------------------------------- {0, 1, 0, 1} {1, 3}In the above example the boolean sequence has ‘true’ values in positions 1 and 3. So the values -13 and -19 in the corresponding positions in the input values sequence are copied to the result sequence
Sample script
A sample script to demonstrate this
selectstatement using xSQL can be run from thesamples/xsql/scripts/financialdirectory with the following command:f 5