IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PostgreSQL Discussion :

Erreur function suite à un dump


Sujet :

PostgreSQL

  1. #1
    Modérateur

    Avatar de MaitrePylos
    Homme Profil pro
    DBA
    Inscrit en
    Juin 2005
    Messages
    5 496
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : Belgique

    Informations professionnelles :
    Activité : DBA
    Secteur : Service public

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 496
    Points : 12 596
    Points
    12 596
    Par défaut Erreur function suite à un dump
    Bonjour, j'ai une function sur une Postgresql 8.0 qui fonctionne nikel,

    je veux faire un dump vers une base 7.4 et là j'ai un problème que je n'arrive pas à régler avec pgadmin3.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    -- Function: insertupdate(int4, date, int4, int4)
     
    -- DROP FUNCTION insertupdate(int4, date, int4, int4);
     
    CREATE OR REPLACE FUNCTION insertupdate(int4, date, int4, int4)
      RETURNS bool AS
    $BODY$
    DECLARE
    heure ALIAS FOR $1;
    jour ALIAS FOR $2;
    formateur ALIAS FOR $3;
    participant ALIAS FOR $4;
    trouve record;
     
    BEGIN
     SELECT INTO trouve * FROM registre
      WHERE regjour=jour
      AND idlogin = formateur
      AND idparticipant = participant;
    IF NOT FOUND THEN
     INSERT INTO registre (regheure,regjour,idlogin,idparticipant)
     VALUES (heure,jour,formateur,participant);
     RETURN 't';
     
    ELSE
     UPDATE registre SET regheure=heure
      WHERE regjour=jour
      AND idlogin = formateur
      AND idparticipant = participant; 
      RETURN 'f';
    END IF;
    RETURN 't';
    END;
    $BODY$
      LANGUAGE 'plpgsql' VOLATILE;
    ALTER FUNCTION insertupdate(int4, date, int4, int4) OWNER TO postgres;
    je n'ai plus en tête comment écrire correctement cette function, apparement le problème se situe au niveau du body.

    Merci de votre aide

  2. #2
    Expert éminent
    Avatar de GrandFather
    Inscrit en
    Mai 2004
    Messages
    4 587
    Détails du profil
    Informations personnelles :
    Âge : 54

    Informations forums :
    Inscription : Mai 2004
    Messages : 4 587
    Points : 7 103
    Points
    7 103
    Par défaut
    Bonjour,

    il faut que tu remplaces les $BODY$ par des simples quotes, et que tu doubles toutes les simples quotes dans le corps de ta fonction.
    FAQ XML
    ------------
    « Le moyen le plus sûr de cacher aux autres les limites de son savoir est de ne jamais les dépasser »
    Giacomo Leopardi

  3. #3
    Modérateur

    Avatar de MaitrePylos
    Homme Profil pro
    DBA
    Inscrit en
    Juin 2005
    Messages
    5 496
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : Belgique

    Informations professionnelles :
    Activité : DBA
    Secteur : Service public

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 496
    Points : 12 596
    Points
    12 596
    Par défaut
    Merci,

    j'ai donc fais ceci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    -- Function: insertupdate(int4, date, int4, int4)
     
    -- DROP FUNCTION insertupdate(int4, date, int4, int4);
     
    CREATE OR REPLACE FUNCTION insertupdate(int4, date, int4, int4)
      RETURNS bool AS
    ' ';
    DECLARE
    heure ALIAS FOR $1;
    jour ALIAS FOR $2;
    formateur ALIAS FOR $3;
    participant ALIAS FOR $4;
    trouve record;
     
    BEGIN
     SELECT INTO trouve * FROM registre
      WHERE regjour=jour
      AND idlogin = formateur
      AND idparticipant = participant;
    IF NOT FOUND THEN
     INSERT INTO registre (regheure,regjour,idlogin,idparticipant)
     VALUES (heure,jour,formateur,participant);
     RETURN "t";
     
    ELSE
     UPDATE registre SET regheure=heure
      WHERE regjour=jour
      AND idlogin = formateur
      AND idparticipant = participant;
      RETURN "f";
    END IF;
    RETURN "t";
    END;
    ' '
      LANGUAGE "plpgsql" VOLATILE;
    ALTER FUNCTION insertupdate(int4, date, int4, int4) OWNER TO postgres;
    j'ai une erreur près de "ALIAS"

  4. #4
    Modérateur

    Avatar de MaitrePylos
    Homme Profil pro
    DBA
    Inscrit en
    Juin 2005
    Messages
    5 496
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : Belgique

    Informations professionnelles :
    Activité : DBA
    Secteur : Service public

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 496
    Points : 12 596
    Points
    12 596
    Par défaut
    Autant pour moi,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    CREATE OR REPLACE FUNCTION insertupdate(int4, date, int4, int4)
      RETURNS bool AS
    '
    DECLARE
    heure ALIAS FOR $1;
    jour ALIAS FOR $2;
    formateur ALIAS FOR $3;
    participant ALIAS FOR $4;
    trouve record;
     
    BEGIN
     SELECT INTO trouve * FROM registre
      WHERE regjour=jour
      AND idlogin = formateur
      AND idparticipant = participant;
    IF NOT FOUND THEN
     INSERT INTO registre (regheure,regjour,idlogin,idparticipant)
     VALUES (heure,jour,formateur,participant);
     RETURN ''t'';
     
    ELSE
     UPDATE registre SET regheure=heure
      WHERE regjour=jour
      AND idlogin = formateur
      AND idparticipant = participant; 
      RETURN ''f'';
    END IF;
    RETURN ''t'';
    END;
    '
      LANGUAGE 'plpgsql' VOLATILE;
    Merci de ton aide

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 3
    Dernier message: 19/10/2006, 21h51
  2. erreur function not defined
    Par reventlov dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 03/04/2006, 01h07
  3. [VB]Erreur: Function must return variant
    Par Empty_body dans le forum VB 6 et antérieur
    Réponses: 9
    Dernier message: 16/02/2006, 12h23
  4. [C#] Erreur générée suite à Response.Redirect
    Par djdada dans le forum ASP.NET
    Réponses: 7
    Dernier message: 18/11/2005, 14h21
  5. [struts][tomcat]erreur 404 suite à un forward
    Par minique dans le forum Struts 1
    Réponses: 3
    Dernier message: 06/09/2004, 10h11

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo