Ingres Community Forums Login Register Ingres.com  

Ingres Community Blogs

A few points of interest from the work that Luminary Solutions do, usually relating to Ingres and Java.

We also do a lot of OpenROAD and .NET development, but I tend to stick to the Java side.
Rate this Entry

Ingres New Features

Submit "Ingres New Features" to Digg Submit "Ingres New Features" to del.icio.us Submit "Ingres New Features" to StumbleUpon Submit "Ingres New Features" to Google
Posted 2009-07-03 at 04:30 AM by Alan.Raison
Updated 2009-07-07 at 08:20 AM by Alan.Raison (Adding comments on ORDER BY clause)

I recently learnt that Ingres 9.2 has introducted the facility to restrict the rows returned from a query by specifying an offset.

Where previously you would only be able to select the first n rows:
SELECT FIRST n col_name FROM table WHERE col_name = 'value';

There is now an "OFFSET" clause:
SELECT FIRST n col_name FROM table WHERE col_name = 'value' OFFSET m;

I went about implementing this in OpenJPA, but found that this dual-location for the Select Range specification was going to cause trouble, so I'd have to override a core method. The problem with that was that the method in question was marked "private", so an override wouldn't have the desired effect! I posted on the developer mailing list about this and they had no problem to me opening up the access, but then I heard about another syntax:

SELECT col_name FROM table WHERE col_name = 'value' OFFSET m FETCH FIRST n ROWS ONLY;

(FIRST can also be replaced by the keyword "NEXT")

This solved my problems, as I was able to specify the range at the end of the query; OpenJPA had a constant for specifying this position (DBDictionary.RANGE_POST_SELECT).

I had a quick play with this new syntax, wondering what
SELECT FIRST x col_name FROM table OFFSET y FETCH NEXT z ROWS ONLY;
would do. Fortunately Ingres prevented me from mixing the FIRST and FETCH FIRST z tokens in a single statement!

Obviously, when restricting the number of rows selected it is important to have a guaranteed ordering, so an ORDER BY clause should also be used. The ORDER BY clause comes before the OFFSET/FETCH FIRST clause.

There's always loads of new features being added to Ingres; these were added in the 9.2 release. For a summary of the new features in a given release, see the Release Summary document; this is currently available for Ingres 9.2 at [url]docs.ingres.com[/url].
Posted in Uncategorized
Views 8920 Comments 2 Edit Tags

« Prev     Main     Next »

Total Comments 2

Comments

  1. Old Comment
    rhann's Avatar
    Perhaps you should add a few words pointing out the extra importance of specifying an ORDER BY clause when using OFFSET and FETCH FIRST to take subsets of the result table, so that I some idea of what I am getting.
    permalink
    Posted 2009-07-06 at 08:12 AM by rhann rhann is online now
  2. Old Comment
    Thanks for the tip Roy, I've updated the text now.
    permalink
    Posted 2009-07-07 at 08:21 AM by Alan.Raison Alan.Raison is offline
 
© 2009 Ingres Corporation. All Rights Reserved