Coder Social home page Coder Social logo

scripts's People

Contributors

matheusb982 avatar

Watchers

James Cloos avatar  avatar

scripts's Issues

PL granos

CREATE OR REPLACE FUNCTION update_easel() RETURNS trigger AS $update_easel_trigger$
DECLARE
old_easel RECORD;
new_easel_id INTEGER;
BEGIN
IF NEW.easel_name IS NOT NULL THEN

      SELECT INTO old_easel * FROM products
      WHERE products.type = 'Easel'
      AND products.easel_name = NEW.easel_name LIMIT 1;

      IF old_easel.eid IS NOT NULL THEN
        UPDATE products SET easel_id = old_easel.eid WHERE pid = NEW.pid;
      ELSE
        INSERT INTO products(
          eid,
          type,
          easel_name,
          material_id,
          product_type_id,
          quality_id,
          thickness_id,
          treatment_id,
          user_id,
          customer_id
        ) VALUES(
          nextval('products_eid_seq'),
          'Easel',
          NEW.easel_name,
          NEW.material_id,
          NEW.product_type_id,
          NEW.quality_id,
          NEW.thickness_id,
          NEW.treatment_id,
          NEW.user_id,
          NEW.customer_id
        ) RETURNING currval('products_eid_seq') into new_easel_id;

        UPDATE products SET easel_id = new_easel_id WHERE pid = NEW.pid;
      END IF;

    END IF;
    RETURN NULL;
  END;
  $update_easel_trigger$ LANGUAGE plpgsql;

  CREATE TRIGGER update_easel_trigger AFTER INSERT ON products FOR EACH ROW EXECUTE PROCEDURE update_easel();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.