Subject | Parametrized views? |
---|---|
Author | PenWin |
Post date | 2010-03-09T09:14:01Z |
I wonder: Is there any support, or any plan for support, for
parametrized views in Firebird? I find myself quite routinely in
situations where I could use them. E.g. I have tables products (id,
name, ...) and sales (product_id, date_and_time, amount, ...) and need
to display product sales in a given period: SELECT products.*,
SUM(amount) FROM products LEFT JOIN sales ON
sales.product_id=products.id WHERE sales.date_and_time BETWEEN
:date_from AND :date_to GROUP BY products.id, .... In this simple case a
manually-built query works well enough, but most of my cases are far
more complex. It would be very useful for me if I could create a view
that would look something like this:
CREATE VIEW sale_sums (PARAM date_from TIMESTAMP, PARAM date_to
TIMESTAMP, product_id, amount) AS SELECT product_id, SUM(amount) FROM
sales WHERE date_and_time BETWEEN :date_from AND :date_to GROUP BY
product_id;
With Firebird 2.1, I can get almost the same functionality with SELECT
... FROM (SELECT ...), but parametrized views would be a lot easier to
read as well as faster to execute.
Pepak
parametrized views in Firebird? I find myself quite routinely in
situations where I could use them. E.g. I have tables products (id,
name, ...) and sales (product_id, date_and_time, amount, ...) and need
to display product sales in a given period: SELECT products.*,
SUM(amount) FROM products LEFT JOIN sales ON
sales.product_id=products.id WHERE sales.date_and_time BETWEEN
:date_from AND :date_to GROUP BY products.id, .... In this simple case a
manually-built query works well enough, but most of my cases are far
more complex. It would be very useful for me if I could create a view
that would look something like this:
CREATE VIEW sale_sums (PARAM date_from TIMESTAMP, PARAM date_to
TIMESTAMP, product_id, amount) AS SELECT product_id, SUM(amount) FROM
sales WHERE date_and_time BETWEEN :date_from AND :date_to GROUP BY
product_id;
With Firebird 2.1, I can get almost the same functionality with SELECT
... FROM (SELECT ...), but parametrized views would be a lot easier to
read as well as faster to execute.
Pepak