CREATE TABLE tabela (
id INTEGER,
vsebina TEXT
);
id
ustvarimo indeks.CREATE INDEX index1 ON tabela (id);
\di
DROP INDEX index1;
CREATE INDEX ime_indeksa ON tabela USING hash (stolpec);
CREATE INDEX ime_indeksa
ON tabela (stolpec1, stolpec2);
CREATE INDEX users_lower_email ON users(lower(email));
WHERE lower(email) = ??
BEGIN
ali BEGIN TRANSACTION
- začetek transakcijeCOMMIT
ali END TRANSACTION
- konec transakcije, shrani spremembeROLLBACK
- razveljavi spremembe\c nova
CREATE TABLE blagajna
(ime TEXT, znesek NUMERIC(10,2));
INSERT INTO blagajna (ime, znesek)
VALUES ('Janez', 10), ('Metka', 10);
BEGIN;
UPDATE blagajna SET znesek = znesek - 5
WHERE ime = 'Janez';
UPDATE blagajna SET znesek = znesek + 5
WHERE ime = 'Metka';
COMMIT;
READ COMMITED
.SET TRANSACTION ISOLATION LEVEL SERIALIZABLE | REPEATABLE READ |
READ COMMITTED | READ UNCOMMITTED;
CREATE FUNCTION function_name(p1 type, p2 type)
RETURNS INTEGER AS
BEGIN
-- koda ...
END;
LANGUAGE language_name;
CREATE FUNCTION povecaj(n INTEGER)
RETURNS INTEGER AS
$$
BEGIN
RETURN n + 1;
END;
$$
LANGUAGE plpgsql;
SELECT povecaj(20);
INSERT
, UPDATE
, DELETE
.CREATE TABLE zaposleni (
id SERIAL PRIMARY KEY,
ime TEXT NOT NULL,
priimek TEXT NOT NULL
);
CREATE TABLE zaposleni_spremembe (
id SERIAL PRIMARY KEY,
zaposleni_id INTEGER NOT NULL,
priimek TEXT NOT NULL,
spremenjeno TIMESTAMP(6) NOT NULL
);
CREATE OR REPLACE FUNCTION belezi_spremembe()
RETURNS trigger AS
$BODY$
BEGIN
IF NEW.priimek <> OLD.priimek THEN
INSERT INTO zaposleni_spremembe
(zaposleni_id, priimek, spremenjeno)
VALUES (OLD.id, OLD.priimek, now());
END IF;
RETURN NEW;
END;
$BODY$ LANGUAGE plpgsql;
Povezava funkcije s prožilcem:
CREATE TRIGGER zadnje_spremembe
BEFORE UPDATE ON zaposleni
FOR EACH ROW EXECUTE PROCEDURE belezi_spremembe();
INSERT INTO zaposleni (ime, priimek)
VALUES ('Janez', 'Novak');
INSERT INTO zaposleni (ime, priimek)
VALUES ('Metka', 'Lepše');
SELECT * FROM zaposleni;
UPDATE zaposleni SET priimek = 'Zelenko' WHERE id = 2;
SELECT * FROM zaposleni;
SELECT * FROM zaposleni_spremembe;
VIEW
)VIEW
)CREATE VIEW ime_pogleda AS
SELECT ...;
DROP VIEW ime_pogleda;
CREATE VIEW samo_priimki_zaposlenih AS
SELECT id, priimek FROM zaposleni;
SELECT * FROM samo_priimki_zaposlenih;
## Ukazi na sistemu
- Ustvarjanje uporabnika v `bash` (interaktivno, navedemo pravice).
```bash
createuser --interactive
```
- Vstop v vlogo (uporabnika).
```bash
sudo -i -u uporabnisko_ime
```
- Izhod iz vloge.
```bash
exit
```
- Ustvarjanje baze.
```bash
createdb ime_baze
```