INFORMIX EXAMPLES
*****************
1. Creating the database

CREATE TABLE infexample
{

       infdate		DATE
       inftime		DATETIME	HOUR TO SECOND
       inftimestamp	DATETIME	YEAR TO SECOND
       infintervalym	INTERVAL	YEAR TO MONTH
       infintervalds	INTERVAL	DAY TO SECOND
}


2. Creating Indexes

CREATE INDEX d ON infexample( infdate );
CREATE INDEX t ON infexample( inftime );
CREATE INDEX ts ON infexample( inftimestamp );

3. Querying the database

Literals:

INSERT INTO infexample [ infdate, inftime, inftimestamp, infintervalym,
                         infintervalds ]
          { VALUES (DATE("1991/01/01"), DATETIME(12:34:56), HOUR TO SECOND, 
	  DATETIME(1997-01-01 12:34:56) YEAR TO SECOND , 
          INTERVAL(3-4) YEAR TO MONTH, 
          INTERVAL(9 23:45:12) DAY TO SECOND  }

           { VALUES (DATE(1994/04/03) DATETIME(10:01:26) HOUR TO SECOND, 
	  DATETIME(1990-08-03 09:23:40) YEAR TO SECOND , 
          INTERVAL(10-2) YEAR TO MONTH, 
          INTERVAL(6 18:06:10) DAY TO SECOND  }	

		
Predicates
Following are examples of temporal predicates in INFORMIX-SQL
All of them give as Result the following record
(1991/01/01, 12:34:56, 1997-01-01 12:34:56, 3-4, 9 23:45:12 )

13. 
    SELECT * 
    FROM   infexample
    WHERE  infdate = DATE("1991/01/01")


    
14. SELECT * 
    FROM   infexample
    WHERE  infdate < DATE("1994/04/03")


15. SELECT * 
    FROM   infexample
    WHERE  infdate <> DATE("1994/04/03")

16. SELECT * 
    FROM   infexample
    WHERE  infdate BETWEEN  DATE("1989/05/07") AND DATE("1992/04/03")

17. SELECT * 
    FROM   infexample
    WHERE  infintervalym = INTERVAL(3-4) YEAR TO MONTH


18. SELECT * 
    FROM   infexample
    WHERE  infintervalym < INTERVAL(10-2) YEAR TO MONTH

19. SELECT * 
    FROM   infexample
    WHERE  infintervalym <> INTERVAL(10-2) YEAR TO MONTH

20. SELECT * 
    FROM   infexample
    WHERE  infintervalds BETWEEN INTERVAL(8 12:01:34) DAY TO SECOND
                         AND     INTERVAL(10 04:03:54) DAY TO SECOND


For examples 21 and 22 

Create a table infexample1 having the same structure as  infexample.

INSERT INTO infexample1 [ infdate, inftime, inftimestamp, infintervalym,
                         infintervalds ]
          { VALUES (NULL,
          DATETIME(08:06:53) HOUR TO SECOND, 
	  DATETIME(1989-08-03 09:23:40) YEAR TO SECOND , 
          NULL, 
          INTERVAL(5 13:07:262), DAY TO SECOND  }


21 & 22. SELECT *
    FROM   infexample1
    WHERE  infdate IS NULL AND
           infintervalym IS NULL
      

23. SELECT * 
    FROM   infexample
    WHERE  infdate <= DATE("1998/07/07") AND
           infdate + infintervalym >= DATE("1992/02/03")

Datetime Constructors
*********************


24.  SELECT * 
     FROM   infexample
     WHERE  infdate = DATETIME(1989-03-01 12:34:56) YEAR TO SECOND + 
                      INTERVAL(1-10) YEAR TO MONTH 
     

25.  SELECT * 
     FROM   infexample
     WHERE  inftimestamp =  INTERVAL(1-10) YEAR TO MONTH  +
                            DATETIME(1997-01-01 12:34:56) YEAR TO SECOND


26.  SELECT * 
     FROM   infexample
     WHERE  inftimestamp = DATETIME(1998-03-07 12:34:56) YEAR TO SECOND -
                           INTERVAL(1-2) YEAR TO MONTH

Queries 29-31 should return a NULL

29. SELECT * 
    FROM   infexample
    WHERE  infdate = TODAY

                           
30. SELECT * 
    FROM   infexample
    WHERE  inftime = CURRENT HOUR TO SECOND

31  SELECT inftimestamp
    FROM   infexample
    WHERE  inftimestamp = CURRENT YEAR TO SECOND

32. SELECT infintervalym
    FROM   infexample
    WHERE  infintervalym = INTERVAL(1-2) YEAR TO MONTH + 
                           INTERVAL(2-2) YEAR TO MONTH

33. SELECT * 
    FROM   infexample
    WHERE  infintervalym = INTERVAL(7-5) YEAR TO MONTH - 
                           INTERVAL(4-1), YEAR TO MONTH


35. SELECT * 
    FROM   infexample
    WHERE  infintervalhs = DATETIME(1997-08-05 12:34:56) YEAR TO SECOND -
                           DATETIME(1994-04-05 12:34:56) YEAR TO SECOND

    Note: Result is an interval with precision of the expression 
          before the minus sign which is .


36. SELECT * 
    FROM   infexample
    WHERE  infintervalhs =  INTERVAL(3 09:03:05) DAY TO SECOND *2

    

41. DATE("1991/01/01")

42. DATETIME(12:34:56) HOUR TO SECOND 

43. EXTEND( EXTEND( DATE( "1991/01/01" ), YEAR TO DAY ), YEAR TO SECOND )
    result is '1991-01-01 00:00:00' 
     

44. EXTEND( DATETIME(12:34:56) HOUR TO SECOND, YEAR TO SECOND )
    results in  '1997-11-29 12:34:56' 
    (assuming 29th November,1997 to be the current date)

45. INTERVAL(3-4) YEAR TO MONTH 

46. INTERVAL(6 18:06:10) DAY TO SECOND 


53. DAY( DATE("1991/01/01") ) gives 01 (integer)












