Builtin

to_table

to_table(a) to_table(a, {sort_attr_list}) to_table(a, {sort_attr_list}, row_limit)

Returns the value of a converted to a table. a must be a relation.

If {sort_attr_list} is passed, it will be used to order the tuples. Use -attr to reverse the sort. You should end with a unique attr for stability in case of tie-breaks.

If row_limit is passed, it will be used to limit the number of tuples in the table (after the ordering).

# can be used as a shorthand (if no limit is needed) e.g.

a# a#{sort_attr_list}

Examples

Note: these results are no longer relations. They are tables, i.e. ordered sets of tuples.

relation
print(to_table($S))
🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕
  SNO   SNAME   STATUS   CITY    
  S2    Jones       10   Paris   
  S1    Smith       20   London  
  S4    Clark       20   London  
  S3    Blake       30   Paris   
  S5    Adams       30   Athens  
🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕

relation, shorthand
print($S#)
🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕
  SNO   SNAME   STATUS   CITY    
  S1    Smith       20   London  
  S2    Jones       10   Paris   
  S3    Blake       30   Paris   
  S4    Clark       20   London  
  S5    Adams       30   Athens  
🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕

relation with ordering
print(to_table($S, {SNAME, SNO}))
🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕
  SNO   SNAME   STATUS   CITY    
  S5    Adams       30   Athens  
  S3    Blake       30   Paris   
  S4    Clark       20   London  
  S2    Jones       10   Paris   
  S1    Smith       20   London  
🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕

relation with ordering and limit
print(to_table($S, {-STATUS, SNO}, 3))
🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕
  SNO   SNAME   STATUS   CITY    
  S3    Blake       30   Paris   
  S5    Adams       30   Athens  
  S1    Smith       20   London  
🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕🮕