apisub_functions.sql 850 Bytes
Newer Older
1
CREATE OR REPLACE FUNCTION unaccent_string(TEXT) RETURNS TEXT AS $$
Stephane Crozat's avatar
Stephane Crozat committed
2
3
4
5
6
7
8
  SELECT translate(
      $1,
      'âãäåÁÂÃÄÅèééêëÈÉÉÊËìíîïìÌÍÎÏÌóôõöÒÓÔÕÖùúûüÙÚÛÜ',
      'aaaaAAAAAeeeeeEEEEEiiiiiIIIIIooooOOOOOuuuuUUUU'
  );
$$ LANGUAGE SQL;

9
CREATE OR REPLACE FUNCTION is_available(TEXT, TEXT, TEXT) RETURNS BOOLEAN AS $$
10
/* Returns True if student has no api validated for same week and year */
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
DECLARE
  student ALIAS FOR $1;
  w ALIAS FOR $2;
  y ALIAS FOR $3;
  c INTEGER;
BEGIN
  SELECT COUNT(*) INTO c
  FROM vsubscription
  WHERE utclogin=student AND week=w AND year=y AND validation;
  IF c = 0 THEN
    RETURN 'TRUE';
  ELSE
    RETURN 'FALSE';
  END IF;
END;
$$ LANGUAGE PLPGSQL;

Stephane Crozat's avatar
Stephane Crozat committed
28
/** TODO **/
29
CREATE OR REPLACE FUNCTION semester(DATE) RETURNS CHAR(1) AS $$
Stephane Crozat's avatar
Stephane Crozat committed
30
31
32
33
BEGIN
  RETURN 'E';
END;
$$ LANGUAGE PLPGSQL;