Subject | Re: How many Unions allowed in firebird Select? |
---|---|
Author | Tony Masefield |
Post date | 2005-11-06T06:05:43Z |
--- In firebird-support@yahoogroups.com, Helen Borrie <helebor@t...>
wrote:
your (and Adam's) point that I should have 'coerced' the data types
myself rather than to 'leave it to chance' - even with the 'Improved
State of the Union' in FB 2! :)
Rgds,
Tony
wrote:
>output, so all
> In unions, the first SELECT determines the structure of the
> all following SELECTs must return rows that are congruent withfirst one
> and matching in data type AND size. (Think of the first SELECT asa sort
> of "mini view definition" :-] )got an
>
> Hence, if you had put the 'Average' query first, you would have
> exception on the second query.field that
>
> As you've discovered, trying to push the result of AVG() into a
> has already been defined as SMALLINT caused an exception becauseAVG()
> doesn't return a SMALLINT.Make it
>
> Also, the output column names are determined by the first select.
> a rule always in SQL to assign identifiers to derived fields (i.e.those
> that are calculated from expressions). Not doing so doesn'tusually cause
> exceptions on the server, since the engine will assign its own(weird)
> names; but it sure can stuff up applications, since the app hasno idea
> what it's looking for when referring to the set's columnidentifiers.
>particularly in
> Firebird 2 has a lot of improvements with regard to unions,
> the area of data coercion. It will actually scan all of theinternal sets
> and, if it can, will coerce a column to the largest compatibletype,
> regardless of the set's position in the union.types
>
> Despite that, IMO, there are plenty of good reasons to coerce the
> yourself so as to write maintainable code and avoid surprises.Thanks for the details on the inner workings of Firebird Helen. Take
>
> ./heLen
>
your (and Adam's) point that I should have 'coerced' the data types
myself rather than to 'leave it to chance' - even with the 'Improved
State of the Union' in FB 2! :)
Rgds,
Tony