TOPIC

Outra forma de fazer fora do URI

Oziel Gonçalves Ferreira asked 1 year ago

CREATE TABLE products (
    id numeric,
    name varchar (50),
    type char,
    price numeric  
);
INSERT INTO products(id,name,type,price)
VALUES
    (1,'Monitor','B',0),
    (2,'Headset','A',0),
    (3,'PC Case','A',0),
    (4,'Computer Desk','C',0),
    (5,'Gaming Chair','C',0),
    (6,'Mouse','A',0);

CREATE OR REPLACE PROCEDURE atualiza(CHAR, CHAR, CHAR)
LANGUAGE plpgsql    
AS $$
BEGIN
    UPDATE products 
    SET price = 20.0
    WHERE type = 'A';

    UPDATE products 
    SET price = 70.0
    WHERE type = 'B';

    UPDATE products 
    SET price = 530.5
    WHERE type = 'C';

    COMMIT;
END;
$$;

CALL atualiza('A','B','C');

SELECT name,
price
FROM products
ORDER BY "type","id" desc;

Remember not post solutions. Your post may be reviewed by our moderators.

  • Ricardo replied 1 year ago

    why procedures? explain please.