diff --git a/plpgsql/README.md b/plpgsql/README.md index 63d144d1..f2f87708 100644 --- a/plpgsql/README.md +++ b/plpgsql/README.md @@ -1,9 +1,25 @@ +# Requirements +You'll need: +- PostgreSQL database, version >= 11 because PROCEDURE keyword isn't supported before [version 11](https://www.postgresql.org/docs/11/release-11.html) +- OS user with local connection privilege to database on standard 5432 port + +To use remote / local dockerized database, add ``` --host --port --username``` parameters to plsql invocation. + # Setup -Create database structure: psql -f ./structure/create.sql -Load code into database psql -f ./code/update_quality.sql -d gilded_rose -Load test data into database: psql -f ./test/data/load.sql -d gilded_rose -Execute: CALL update_quality(); -Check results: SELECT * FROM items; +In shell: +- create database: ```createdb gilded_rose``` +- create item table (structure): ```psql -d gilded_rose -f ./structure/create.sql``` +- load code into database: ```psql -d gilded_rose -f ./code/update_quality.sql ``` + +If you get this message```LINE 1: CREATE OR REPLACE PROCEDURE public.update_quality()```, your PostgreSQL version may under 11, consider upgrading. + +# Interactive run +In shell: +- load test data into database: ```psql -d gilded_rose -f ./test/data/load.sql``` +- connect to CLI: ```psql -d gilded_rose``` +- check item state: ```SELECT * FROM item;``` +- execute item update: ```CALL update_quality();``` +- check item state: ```SELECT * FROM item;``` # Test No test code provided, only a sample of test data diff --git a/plpgsql/structure/create.sql b/plpgsql/structure/create.sql index 5ce4d245..263b860d 100644 --- a/plpgsql/structure/create.sql +++ b/plpgsql/structure/create.sql @@ -1,7 +1,3 @@ -CREATE DATABASE gilded_rose; - -\connect gilded_rose; - CREATE TABLE item ( name CHARACTER VARYING(100) NOT NULL, sellIn INTEGER,