21.10.2013 Views

Firebird 2.1 Language Reference Update

Firebird 2.1 Language Reference Update

Firebird 2.1 Language Reference Update

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

DML statements<br />

• Only non-negative whole number literals are interpreted as column positions. A whole number resulting from<br />

an expression evaluation or parameter substitution is seen as an integer invariable and will lead to a dummy<br />

sort, since its value is the same for each row.<br />

NULLs placement<br />

Changed in: 1.5, 2.0<br />

Description: <strong>Firebird</strong> 1.5 has introduced the per-column NULLS FIRST and NULLS LAST directives to specify<br />

where NULLs appear in the sorted column. <strong>Firebird</strong> 2.0 has changed the default placement of NULLs.<br />

Unless overridden by NULLS FIRST or NULLS LAST, NULLs in ordered columns are placed as follows:<br />

• In <strong>Firebird</strong> 1.0 and 1.5: at the end of the sort, regardless whether the order is ascending or descending.<br />

• In <strong>Firebird</strong> 2.0 and up: at the start of ascending orderings and at the end of descending orderings.<br />

See also the table below for an overview of the different versions.<br />

Table 6.1. NULLs placement in ordered columns<br />

Ordering<br />

79<br />

NULLs placement<br />

<strong>Firebird</strong> 1 <strong>Firebird</strong> 1.5 <strong>Firebird</strong> 2<br />

order by Field [asc] bottom bottom top<br />

order by Field desc bottom bottom bottom<br />

order by Field [asc | desc] nulls first — top top<br />

order by Field [asc | desc] nulls last — bottom bottom<br />

Examples:<br />

Notes<br />

• Pre-existing databases may need a backup-restore cycle before they show the correct NULL ordering behaviour<br />

under <strong>Firebird</strong> 2.0 and up.<br />

• No index will be used on columns for which a non-default NULLS placement is chosen. In <strong>Firebird</strong> 1.5, that<br />

is the case with NULLS FIRST. In 2.0 and higher, with NULLS LAST on ascending and NULLS FIRST on<br />

descending sorts.<br />

select * from msg<br />

order by process_time desc nulls first<br />

select * from document<br />

order by strlen(description) desc<br />

rows 10<br />

select doc_number, doc_date from payorder<br />

union all<br />

select doc_number, doc_date from budgorder<br />

order by 2 desc nulls last, 1 asc nulls first

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!