Re: Triggers In Informix?
Posted in 1995
Topics: SQL Development & Query Writing, Connectivity: ESQL/C, 4GL & Embedded SQL, Triggers, Constraints & Referential Integrity
Steve Huff (sh5@ornl.gov) wrote:
: 1. Does Informix support the definition of database "triggers" to allow some
: defined activity (e.g. "update") on a column or row to automatically fire off
: some pre-defined code?
Yes. Informix engines (both SE and OnLine) support
triggers starting from version 5.0
: If so, where can I find information about how to do
: this? I need to recalculate the value in one table every time one of the
: contributing values in another tables gets updated.
Try "Using triggers" Informix manual.
: 2. Is there anyway that I can cause a SELECT statement to return every
: nth row from the rows satisfying the WHERE clause, where n is a parameter I
: specify at the time of SELECT? Or equally acceptable to return a random
: sample of size n% from the rows satisfying the WHERE clause?
If you are using 4GL then you can always use same kind of counter
while fetching rows (its obvious, I suppose).
However, in "pure" SQL it may be somewhat difficult.
My approach:
1) create temporary table with all the columns your query returns
plus additional serial column, eg.
CREATE TEMP TABLE mytemp ( mycol1 INT, mycol2 CHAR, sss SERIAL )2) now run your "base" query the following way:
INSERT INTO mytemp
( SELECT mycol1, mycol2, 0
FROM mytab
WHERE .... )3) and if you want every third row you can run such a query:
SELECT *
FROM mytemp
WHERE ((sss/3)-trunc(sss/3)) = 04) drop temporary table
I hope it works (had no possibility to check).
Best regards,
Mariusz
--
-------------------------------------------------------------
Mariusz Ostrowski mariusz@nask.org.pl
Research and Academic Computer Networks Warsaw, Poland
-------------------------------------------------------------