The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

SQL::Builder::Junction - Represent a SQL junction, typically including INTERSECT, UNION, and EXCEPT

SYNOPSIS

        my $junction = SQL::Builder::Junction->new();

        $junction->list_push("SELECT 1");
        $junction->list_push("SELECT 2");

        $junction->junction("INTERSECT");

        # SELECT 1 INTERSECT SELECT 2
        print $junction->sql;

        $junction->junction("EXCEPT");
        
        # SELECT 1 EXCEPT SELECT 2
        print $junction->sql;

        $junction->junction("UNION");
        $junction->all(1);

        # SELECT 1 UNION ALL SELECT 2
        print $junction->sql

DESCRIPTION

This is a SQL::Builder::List(3) subclass. Make sure to see the following classes for common junctions

        SQL::Builder::Intersect(3)
        SQL::Builder::Except(3)
        SQL::Builder::Union(3)

METHODS

all([1|0])

Turn on/off the 'ALL' keyword used in sql(). Turned off by default. When called with arguments, the value is set and current object is returned; otherwise, the current value is returned. If this is on, the 'ALL' keyword will be used between all items in the list

init()

Calls the init() method of the parent class and sets the joiner() value to undef.

junction([$j])

Get/set the junction value. This is a wrapper to SQL::Builder::List::joiner()

sql()

Return the SQL serialization or an empty string if the list is empty. If the junction() value is not defined with a length, then an exception is thrown. The value of junction() is passed through SQL::Builder::Base::dosql() before being used.

children()

Return a SQL::Builder::Iterator object to first iterate over the value of junction(), then if list() is an array its elements are included, otherwise the value of list() is used directly. Basically:

        $self->junction,
        ref $self->list eq 'ARRAY' ? @{$self->list} : $self->list

SEE ALSO

SQL::Builder::Intersect(3) SQL::Builder::Except(3) SQL::Builder::Union(3) SQL::Builder::List(3) SQL::Builder::Select(3) SQL::Builder::Base(3)