Chapter 2. Database

This text is located in start.sgml and is just a general description of the application databases.

MyDB

Date: 2000-12-31.

COMMENT ON DATABASE mydb IS 'Write comment here'

Tables

Table: customer

COMMENT ON TABLE customer IS 'Write comment here'

Table 2-1. customer

ColumnTypeDescription
custidint4COMMENT ON COLUMN customer.custid IS 'Write comment here'
nametextCOMMENT ON COLUMN customer.name IS 'Write comment here'

Table: inventory

COMMENT ON TABLE inventory IS 'Write comment here'

Table 2-2. inventory

ColumnTypeDescription
invidint4COMMENT ON COLUMN inventory.invid IS 'Write comment here'
nametextCOMMENT ON COLUMN inventory.name IS 'Write comment here'

Views

View: custview

COMMENT ON VIEW custview IS 'Write comment here'

CREATE VIEW custview AS 'SELECT * FROM customer WHERE name=''John'''

View: invenview

COMMENT ON VIEW invenview IS 'Write comment here'

CREATE VIEW invenview AS 'SELECT * FROM inventory WHERE name=''Chair'''

Functions

Function: getid(text)

COMMENT ON FUNCTION getid(text) IS 'Write comment here'

CREATE FUNCTION getid(text) RETURNS INT4 AS '
  DECLARE
    p_name ALIAS FOR $1;
    id INT4;
  BEGIN
    SELECT custid INTO id FROM customer WHERE name=p_name;
    IF NOT FOUND THEN
      RETURN 0;
    END IF;
    RETURN id;
  END;
' LANGUAGE 'PGplSQL';