Subject RE: [firebird-support] Replacing views with select procedures
Author Alan McDonald
> >The syntax in your second statement is, unfortunately, not
> reasonable, since
> >you are trying to select 3 fields in a select statement slot which is
> >expecting one and only one field value. No wonder it barfs.
> >
> > FOR SELECT address.id, address, street, street_type, suite,
> > (SELECT city FROM get_zipinfo(:zipcode_id) as city,
> > (SELECT state FROM get_zipinfo(:zipcode_id) as state,
> > (SELECT zipcode FROM get_zipinfo(:zipcode_id) as zipcode
> >
> >would have worked.
> >Alan
> >
> >
> Thank you! That makes sense - even if I think it's unreasonable for an
> otherwise perfectly good parser to not be able figure that out
> <g>. Sheesh.
>
> Now that I know how - is there a preferred method for this kind of thing
> - inline selects versus forselect constructs? Or is it another example
> of Firebird flexibility and it's just personal preference?
>
> Daniel

inline vs for select? there is no Vs here... what do you mean?
inline versus join syntax.. there is a Vs here.
I personally like inline selects because they are easier to read than joins
but I understand they are less efficient. They may be, but they are still
well within acceptable limits for me.
Joins are by far the most efficient and they should be SQL99 compliant
rather than the SQL92 you have
e.g.
SELECT address.id, address, street, street_type, suite, zipcode_id
FROM address, street_types
WHERE address.id = :address_id and street_type_id = street_types.id

should be
SELECT address.id, address.address, address.street,
street_types.street_type, address.suite, address.zipcode_id
FROM address join street_types on address.street_type_id =
street_types.id
WHERE address.id = :address_id

better still to use aliases for readability

SELECT a.id, a.address, a.street, a.suite, a.zipcode_id, s.street_type
FROM address a join street_types s on a.street_type_id = s.id
WHERE a.id = :address_id

The FOR SELECT ... INTO is still required to read those values into return
parameters.
FOR SELECT a.id, a.address, a.street, a.suite, a.zipcode_id, s.street_type
FROM address a join street_types s on a.street_type_id = s.id
WHERE a.id = :address_id
INTO .. whatever
DO SUSPEND

Alan