Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
38
Добавлен:
18.03.2015
Размер:
608.7 Кб
Скачать

SQL Language Enhancements

FIRST and SKIP Elements

The FIRST clause is also optional, i.e. you can include SKIP in a statement without FIRST to get an output set that simply excludes the rows appointed to SKIP.

Example

SELECT SKIP (5+3*5) * FROM MYTABLE;

SELECT FIRST (4-2) SKIP ? * FROM MYTABLE;

SELECT FIRST 5 DISTINCT FIELD FROM MYTABLE;

Two Gotchas with SELECT FIRST

1. This:

delete from TAB1

where PK1 in (select first 10 PK1 from TAB1);

will delete all of the rows in the table. Ouch! the sub-select is evaluating each 10 candidate rows for deletion, deleting them, slipping forward 10 more...ad infinitum, until there are no rows left. Beware!

2. Queries like:

...

WHERE F1 IN ( SELECT FIRST 5 F2 FROM TABLE2 ORDER BY 1 DESC )

won't work as expected, because the optimization performed by the engine transforms the correlated WHERE...IN (SELECT...) predicate to a correlated EXISTS predicate. It's obvious that in this case FIRST N doesn't make any sense:

...

WHERE EXISTS (

SELECT FIRST 5 TABLE2.F2 FROM TABLE2 WHERE TABLE2.F2 = TABLE1.F1

ORDER BY 1 DESC )

Other Firebird 1.0.x Features

The remaining items in this section are DML enhancements that were introduced in Firebird 1.0.x, described again for the reader's convenience.

(1.0) GROUP BY UDF

It is now possible to aggregate a SELECT by grouping on the output of a UDF. e.g.

38

Соседние файлы в папке doc