• Antelope Release 5.10 Linux CentOS release 7.6.1810 (Core) 3.10.0 2020-05-12

 

NAME

dbjoin, dbtheta - join two database tables

SYNOPSIS

#include "db.h" ;

Dbptr dbjoin(Dbptr db1, Dbptr db2, Tbl **pattern1,
                 Tbl **pattern2, int outer,
                 Tbl **nojoin, char *name)

Dbptr dbtheta(Dbptr db1, Dbptr db2, char *ex_str,
                 int outer, char *name)

DESCRIPTION

dbjoin creates a new view which is a natural join of the two database tables specified by db1 and db2. The tables are joined by the keys specified in the pattern1 and pattern2 arguments; if these are zero, by fields inferred from the common keys of the two tables.

dbtheta creates a new view which is a theta join of the two database tables specified by db1 and db2. A new record is created in the new view whenever the expression specified by ex_str evaluates to true.

For some records in the first table, there may be no matching record in the second table. This would normally mean that there would be no corresponding record in the joined table. However, you may force an entry for every record in the first table by setting outer non-zero. If there is no matching record in the second table, then the null record is used.

The new view is named as specified by name; if this is zero, then a unique name is generated.

OPTIONS

The join keys may be explicitly specified with pattern1 and pattern2. Alternatively, if pattern1 and pattern2 are pointers to zero, the inferred join keys are returned in pattern1 and pattern2. Finally, if pattern1 and pattern2 are zero, the join keys are inferred, but not returned.

EXAMPLE

The following performs an outer join of two tables by the inferred keys.

Dbptr db1, db2 ;
    .
    .
    .

    db = dbjoin ( db, db2, 0, 0, 1, 0, 0 ) ;
    if ( db.table == dbINVALID )
        die ( 1, "Join fails at table: %s\n",
                                db2_table_name ) ;

RETURN VALUES

The return value is a database pointer to the new view of the joined tables, or a database pointer of all dbINVALID if the join failed. The routines may also return lists of join keys; these lists should be freed with a call to freetbl:

    freetbl(pattern1,0) ;
    freetbl(pattern2,0) ;

LIBRARY

$(DBLIBS)

DIAGNOSTICS

SEE ALSO

dbintro(3)
dbsort(3)
shellsort(3)
quicksort(3)

AUTHOR

Daniel Quinlan
Printer icon