0

Code:

DROP function IF EXISTS update_rarity;
CREATE OR REPLACE FUNCTION  update_rarity() RETURNS trigger AS $$
BEGIN
    if  (((select count(raresa) FROM Carta WHERE c.raresa LIKE '%Legendary%')*100  /(select count(raresa) FROM Carta)) <> 17 ) then
        INSERT INTO Warnings(affected_table,error_message,date,user)
        VALUES ('Carta' ,'Proporcions de raresa no respectades: Legendary la proporció actual és '|| (select count(raresa) FROM Carta WHERE raresa LIKE '%Legendary%')  || 'quan hauria de ser 3', CURRENT_DATE, CURRENT_USER);
    end if;
    
    return null;    
END; 
$$ LANGUAGE plpgsql; 

DROP TRIGGER IF EXISTS cards ON Carta;
CREATE OR REPLACE TRIGGER cards
AFTER INSERT OR UPDATE ON  Carta
FOR EACH ROW
EXECUTE FUNCTION update_rarity();
UPDATE carta  SET nom ='Ral Roachs Rascals' ,raresa='Proletari' WHERE nom = 'Rascals';
ERROR:  syntax error in or near of «;»
LINE 1: DROP function IF EXISTS update_rarity;
                                             ^
SQL state: 42601
Character: 38
1
  • 1
    Postgres 9.5 is no longer supported you should plan an upgrade as soon as possible. Your code would work with all supported Postgres versions. Commented Jun 30, 2022 at 8:40

1 Answer 1

2

The possibility to omit the function signature for a DROP FUNCTION was introduced in Postgres 10. In your outdated and unsupported Postgres version, you need to include the parameter list (which is empty for a trigger function):

DROP function IF EXISTS update_rarity();
                                     ^-- this
Sign up to request clarification or add additional context in comments.

1 Comment

Okey thank you for all,you are alright,it is the version.Solutioned

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.