preferences.sql 1.1 KB

123456789101112131415161718192021222324
  1. CREATE TABLE IF NOT EXISTS vote.preferences
  2. (
  3. date_creation timestamp without time zone NOT NULL DEFAULT now(),
  4. date_modification timestamp without time zone,
  5. numero_preference integer NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
  6. numero_participant integer NOT NULL,
  7. numero_traitement integer NOT NULL,
  8. valeurs character varying(4000) COLLATE pg_catalog."default",
  9. CONSTRAINT fk_numeroParticipantPreference FOREIGN KEY(numero_participant) REFERENCES vote.participants(numero_participant)
  10. )
  11. TABLESPACE vote;
  12. ALTER TABLE IF EXISTS vote.preferences OWNER to vote;
  13. CREATE INDEX IF NOT EXISTS ix_numeroParticipantPreference ON vote.preferences USING btree (numero_participant) TABLESPACE vote;
  14. CREATE FUNCTION vote.dateModificationPreference() RETURNS TRIGGER AS $$
  15. BEGIN
  16. NEW.date_modification = now();
  17. return NEW;
  18. END;
  19. $$ LANGUAGE 'plpgsql';
  20. ALTER FUNCTION vote.dateModificationPreference() OWNER TO vote;
  21. CREATE OR REPLACE TRIGGER dateModificationPreference BEFORE UPDATE ON vote.preferences FOR EACH ROW EXECUTE FUNCTION vote.dateModificationPreference();