Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| labs:postgresql [2009/07/06 20:58] – admin | labs:postgresql [2017/07/25 16:22] (current) – [Update Statements] admin | ||
|---|---|---|---|
| Line 13: | Line 13: | ||
| You can use * to mean all columns in the table. | You can use * to mean all columns in the table. | ||
| + | |||
| + | === Explanation of Various Joins === | ||
| + | |||
| + | The picture below comes from [[http:// | ||
| + | |||
| + | {{http:// | ||
| + | |||
| ==== Insert Statements ==== | ==== Insert Statements ==== | ||
| Line 44: | Line 51: | ||
| + | To update a table with a value in another table: | ||
| + | | ||
| + | update table2 set t2field = t1.field from table1 t1 where table2.keyfield2 = t1.keyfield1; | ||
| ===== Creating Database ===== | ===== Creating Database ===== | ||
| Line 53: | Line 63: | ||
| ===== Creating Tables ===== | ===== Creating Tables ===== | ||
| - | ==== Creating Sequences ==== | + | |
| + | Example: | ||
| + | |||
| + | CREATE TABLE table_name ( | ||
| + | id integer NOT NULL default nextval(' | ||
| + | eagle_id char(9), | ||
| + | floor_to_graffito_height varchar(30), | ||
| + | description text, | ||
| + | comment text, | ||
| + | translation text, | ||
| + | FOREIGN KEY ( eagle_id ) REFERENCES EAGLE_inscriptions(id), | ||
| + | PRIMARY KEY (id) | ||
| + | ); | ||
| + | ===== Creating Sequences | ||
| | | ||
| - | ==== Viewing Table Information ==== | + | ===== Viewing Table Information |
| You may want to look at a table' | You may want to look at a table' | ||
| Line 85: | Line 108: | ||
| SELECT * FROM pg_roles; | SELECT * FROM pg_roles; | ||
| + | ==== Creating User ==== | ||
| + | |||
| + | CREATE USER username [WITH PASSWORD '' | ||
| + | |||
| + | Or | ||
| + | |||
| + | createuser | ||
| + | |||
| + | ==== Adding user to groups ==== | ||
| + | |||
| + | ALTER GROUP groupname ADD user username [, ... ] | ||
| ==== Granting Permissions ==== | ==== Granting Permissions ==== | ||
| Line 105: | Line 139: | ||
| ALTER TABLE table_name ADD COLUMN col_name type ... | ALTER TABLE table_name ADD COLUMN col_name type ... | ||
| + | |||
| + | === Change Column === | ||
| + | |||
| + | ALTER TABLE quizzes ALTER COLUMN name TYPE varchar(30); | ||
| ==== Dump Data Base ==== | ==== Dump Data Base ==== | ||
| pg_dump < | pg_dump < | ||
| + | |||
| + | ==== Connecting to Another Database ('' | ||
| + | |||
| + | \c dbname | ||
