Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Z91p8-0007KX-Ac for pgsql-admin@arkaria.postgresql.org; Sun, 28 Jun 2015 01:55:58 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1Z91p7-0003qw-5R for pgsql-admin@arkaria.postgresql.org; Sun, 28 Jun 2015 01:55:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1Z8g65-0003rM-4h for pgsql-admin@postgresql.org; Sat, 27 Jun 2015 02:44:01 +0000 Received: from mbob.nabble.com ([162.253.133.15]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1Z8g5x-00024v-8J for pgsql-admin@postgresql.org; Sat, 27 Jun 2015 02:44:00 +0000 Received: from msam.nabble.com (unknown [162.253.133.85]) by mbob.nabble.com (Postfix) with ESMTP id C59BCFDC621 for ; Fri, 26 Jun 2015 19:44:31 -0700 (PDT) Date: Fri, 26 Jun 2015 19:43:48 -0700 (MST) From: litu16 To: pgsql-admin@postgresql.org Message-ID: <1435373028918-5855422.post@n5.nabble.com> Subject: SELECT column WHERE (type = 'S' OR type = 'B') but perform different actions depending on whether type = 'S' or 'B' MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -0.3 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-admin Precedence: bulk Sender: pgsql-admin-owner@postgresql.org Hi all, this is my table... 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. -- Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-admin