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


Mon, 30 Mar 2015

postgreSQL Database Versioning

   create table public.db_version (modname varchar(15) primary key,
                                   modvers varchar(5) not null,
                                   install_complete boolean default false );

    insert into public.db_version VALUES ('MYMODULE','1.0',false);

    -- put actual table/view/stored procedures here

    update public.db_version set install_complete = true where mod_name = 'MYMODULE' 
         and modvers = '1.0';



posted at: 21:37 | 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.