by Joel Limardo
Home | Twitter | LinkedIn | Consulting | About | RSS | Map
Areas:
Process
 
Technical
 
Projects:


Wed, 30 Nov 2016

Case Statement

Table:


test=> \d foobar;
                        Table "public.foobar"
  Column  |         Type          |             Modifiers 
----------+-----------------------+----------------------------------- id | character varying(20) | not null longdesc | character varying(15) | superid | character varying(15) | default 'none'::character varying Indexes: "foobar_pkey" PRIMARY KEY, btree (id)

Case Statement:

 select id, CASE WHEN id::integer > 1 THEN 'GREATER_THAN_ONE' ELSE   'NOT_GREATER_THAN_ONE' END as P from foobar;

Function that Tries the Same Thing:


CREATE OR REPLACE FUNCTION mydecode(varchar) RETURNS varchar AS $$
    BEGIN
    IF $1::integer > 1 THEN
        RETURN ( 'GREATERTHANONE');
    ELSE
        RETURN ('NOTGREATER-THAN_ONE');
    END IF;
    END;
   $$ LANGUAGE plpgsql;

END;



posted at: 15:52 | path: /technical/DB/postgreSQL | this entry | top

postgreSQL Projects

  1. Database Versioning
  2. Case Statement
  3. Try PostgreSQL Cloud Service


posted at: 15:46 | path: /technical/DB/postgreSQL | this entry | top

© 2015-2017. All Rights Reserved. All original code appearing on this site is MIT Licensed unless otherwise noted.