From: litu16 <litumelendez@gmail.com>
To: pgsql-admin@postgresql.org
Subject: SELECT column WHERE (type = 'S' OR type = 'B') but perform different actions depending on whether type = 'S' or 'B'
Date: Fri, 26 Jun 2015 19:43:48 -0700 (MST)
Message-ID: <1435373028918-5855422.post@n5.nabble.com> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-admin>
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-depe...
Sent from the PostgreSQL - admin mailing list archive at Nabble.com.
--
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-admin@postgresql.org
Cc: litumelendez@gmail.com
Subject: Re: SELECT column WHERE (type = 'S' OR type = 'B') but perform different actions depending on whether type = 'S' or 'B'
In-Reply-To: <1435373028918-5855422.post@n5.nabble.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox