Next Employee ID - Mailing list pgsql-sql

From Herbert Rabago Ambos
Subject Next Employee ID
Date
Msg-id Pine.LNX.4.10.10002260808001.30045-100000@hindang.msuiit.edu.ph
Whole thread Raw
List pgsql-sql
Hi,

I've been trying to find out what's wrong with my function:

create function Next_Employee_ID() returns text AS '
declare       Emp             as RECORD;       CurYear         as text;       NextEmpYrNo     as int;

begin       -- get current year       CurYear := substr( datetime_text(now()), 21,4);
       -- read latest employee.id       Select max(id) into Emp from Employee               Where id like CurYear ||
''%'';
       if not found then               -- create new sequence starting from "current year" +    -- "-001"::text
     return CurYear || ''-001'';       else               -- extract last 3 chars -- convert it to int -- add 1
     NextEmpYrNo := substr(Emp.max, 6, 3)::int + 1;               return CurYear || ''-'' || NextEmpYrNo::text;
endif;
 
end;' language 'plpgsql';


I have an employee table who have an field named id of type varchar(8);


herbert



pgsql-sql by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: [SQL] how to create index on timestamp field in pre v7 database
Next
From: Mark Kirkwood
Date:
Subject: New Optimizer Behaviour In 7.0b1