Commit f63c4eaa authored by Stephane Crozat's avatar Stephane Crozat
Browse files

Fixing vlocaluser (joining need to suppr accents), + few enhancements

parent 36b15429
...@@ -47,11 +47,25 @@ CREATE TABLE utcstudent ( ...@@ -47,11 +47,25 @@ CREATE TABLE utcstudent (
\COPY utcstudent (firstname,surname,speciality,level) FROM '/home/stc/inscriptions_A18.csv' WITH CSV HEADER DELIMITER ';' QUOTE '"' \COPY utcstudent (firstname,surname,speciality,level) FROM '/home/stc/inscriptions_A18.csv' WITH CSV HEADER DELIMITER ';' QUOTE '"'
*/ */
CREATE VIEW vlocaluser AS CREATE OR REPLACE FUNCTION unaccent_string(TEXT)
RETURNS TEXT
IMMUTABLE
STRICT
LANGUAGE SQL
AS $$
SELECT translate(
$1,
'âãäåÁÂÃÄÅèééêëÈÉÉÊËìíîïìÌÍÎÏÌóôõöÒÓÔÕÖùúûüÙÚÛÜ',
'aaaaAAAAAeeeeeEEEEEiiiiiIIIIIooooOOOOOuuuuUUUU'
);
$$;
CREATE OR REPLACE VIEW vlocaluser AS
SELECT l.utclogin, u.surname, u.firstname, MAX(u.speciality) AS speciality, MAX(u.level) AS level, SELECT l.utclogin, u.surname, u.firstname, MAX(u.speciality) AS speciality, MAX(u.level) AS level,
CASE WHEN COUNT(*)>1 THEN 'duplication' END AS warning CASE WHEN COUNT(*)>1 THEN 'duplication' END AS warning,
l.utclogin || 'etu.utc.fr' AS utcmail
FROM localuser l FROM localuser l
LEFT JOIN utcstudent u ON l.surname=u.surname AND l.firstname=u.firstname LEFT JOIN utcstudent u ON l.surname=u.surname AND l.firstname=unaccent_string(u.firstname)
GROUP BY l.utclogin, u.surname, u.firstname; GROUP BY l.utclogin, u.surname, u.firstname;
/** Test dataset /** Test dataset
...@@ -72,14 +86,14 @@ ap.code, ...@@ -72,14 +86,14 @@ ap.code,
CASE WHEN ap.code<10 THEN '000'||ap.code WHEN ap.code>=10 THEN '00'||ap.code END AS normcode, CASE WHEN ap.code<10 THEN '000'||ap.code WHEN ap.code>=10 THEN '00'||ap.code END AS normcode,
ap.name, ap.year, ap.semester, ap.name, ap.year, ap.semester,
TO_CHAR(ap.dbegin,'TMday FMDD TMmonth') AS dbegin, TO_CHAR(ap.dend,'TMday FMDD TMmonth') AS dend, TO_CHAR(ap.dbegin,'TMday FMDD TMmonth') AS dbegin, TO_CHAR(ap.dend,'TMday FMDD TMmonth') AS dend,
ap.size, ap.ects, ap.mail, ap.mail, ap.ects, ap.size,
COUNT(su.utclogin) AS nbsub COUNT(su.utclogin) AS nbsub
FROM api ap LEFT JOIN subscribe su ON ap.code=su.api FROM api ap LEFT JOIN subscribe su ON ap.code=su.api
GROUP BY ap.code, normcode, ap.name, ap.year, ap.semester, dbegin, dend, ap.size, ap.ects, ap.mail GROUP BY ap.code, normcode, ap.name, ap.year, ap.semester, dbegin, dend, ap.size, ap.ects, ap.mail
ORDER BY ap.year, ap.semester, ap.dbegin, ap.dend, ap.code; ORDER BY ap.year, ap.semester, ap.dbegin, ap.dend, ap.code;
CREATE OR REPLACE VIEW vsubscription AS CREATE OR REPLACE VIEW vsubscription AS
SELECT ap.*, TO_CHAR(su.subdate,'DD/MM/YYYY') AS subdate, su.utclogin, lo.firstname, lo.surname, lo.speciality, lo.level SELECT ap.*, TO_CHAR(su.subdate,'DD/MM/YYYY') AS subdate, su.utclogin AS sublogin, lo.*
FROM subscribe su FROM subscribe su
JOIN vapi ap ON ap.code=su.api JOIN vapi ap ON ap.code=su.api
LEFT JOIN vlocaluser lo ON su.utclogin=lo.utclogin LEFT JOIN vlocaluser lo ON su.utclogin=lo.utclogin
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment