-- Table: dept

CREATE TABLE dept
(
    deptno numeric(2) NOT NULL,
    dname character varying(14),
    loc character varying(13),
    CONSTRAINT dept_pk PRIMARY KEY (deptno),
    CONSTRAINT dept_dname_uq UNIQUE (dname)
);

ALTER TABLE dept OWNER TO postgres;
GRANT ALL ON TABLE dept TO postgres;
GRANT ALL ON TABLE dept TO public;

-- Column level privileges
GRANT REFERENCES(dname) ON dept TO ashesh;
GRANT SELECT(dname) ON dept TO ash;

-- CREATE GROUP "ash,asdf"
-- create a group with ',' (comma)
CREATE ROLE "ash,asdf" SUPERUSER INHERIT NOCREATEDB NOCREATEROLE;

-- Table: foo
CREATE TABLE foo
(
    bar integer,
    baz integer
)
WITH (OIDS=FALSE);
ALTER TABLE foo OWNER TO postgres;
GRANT ALL ON TABLE foo TO postgres;
GRANT ALL ON TABLE foo TO public;

-- Column level privileges
GRANT SELECT(baz), INSERT(bar, baz), REFERENCES(bar) ON foo TO "ash,asdf";
GRANT SELECT(bar), UPDATE(bar, baz) ON foo TO "ash,asdf" WITH GRANT OPTION;

-- View: vfoo
CREATE VIEW vfoo AS SELECT * FROM foo;
GRANT SELECT(bar), INSERT(bar), REFERENCES(bar) ON vfoo TO "ash,asdf";
GRANT INSERT(baz) ON vfoo TO "ash,asdf" WITH GRANT OPTION;
