Hi all, this is my table...
<http://postgresql.nabble.com/file/n5855422/screenshot.jpg>
I only want to select **one** "time" row, **either** WHERE "time_type" =
'Start' OR "time_type" = 'Break', **but only one**, the one that is at the
bottom row (descending) (ORDER BY "fn_serial" DESC LIMIT 1).
Im successfully doing it by using this Trigger Function...
* CREATE OR REPLACE FUNCTION timediff()
RETURNS trigger AS
$BODY$
DECLARE
prevtime character varying;
BEGIN
SELECT t.time FROM table_ebscb_spa_log04 t WHERE t.fn_name = NEW.fn_name
AND (t.time_type = 'Start' OR time_type = 'Break') ORDER BY t.fn_serial DESC
LIMIT 1 INTO prevtime;
IF NOT FOUND THEN
RAISE EXCEPTION USING MESSAGE = 'NOT FOUNDED';
ELSE
NEW.time_elapse := prevtime
END IF;
return NEW;
END
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION timediff()
OWNER TO postgres;*
But in my script I would like to perform different actions depending on
whether "fn_type" = 'Start' OR "fn_type = 'Break', I mean where "prevtime"
variable came from, eg:
* IF "prevtime" came from "fn_type" = 'Start' THEN
RAISE EXCEPTION USING MESSAGE = 'PREVTIME CAME FROM START';
ELSIF "prevtime" came from "fn_type" = 'BREAK' THEN
RAISE EXCEPTION USING MESSAGE = 'PREVTIME CAME FROM BREAK';*
I can guess a way to do that, but its redundant, So I would like to ask
suggestions from good PostgreSQL fellow programmers.
Thanks Advanced.
--
View this message in context:
http://postgresql.nabble.com/SELECT-column-WHERE-type-S-OR-type-B-but-perform-different-actions-depending-on-whether-type-S-or-B-tp5855422.html
Sent from the PostgreSQL - admin mailing list archive at Nabble.com.