PostgreSQL Cheat Sheet
PostgreSQL Cheat Sheet
12/31/2005 09:34 PM
CREATE TABLE tableName ( id serial PRIMARY KEY, name varchar(50) UNIQUE NOT NULL, dateCreated timestamp DEFAULT current_timestamp );
Add a primary key
PREPARE preparedInsert (int, varchar) AS INSERT INTO tableName (intColumn, charColumn) VALUES ($1, $2); EXECUTE preparedInsert (1,'a'); EXECUTE preparedInsert (2,'b'); DEALLOCATE preparedInsert;
Create a Function
CREATE OR REPLACE FUNCTION month (timestamp) RETURNS integer AS 'SELECT date_part(''month'', $1)::integer;' LANGUAGE 'sql';
Table Maintenance
12/31/2005 09:34 PM
SHOW ALL;
Grant all permissions to a user
Basic SQL
Get all columns and rows from a table
bookmark this
digg this
Prints in under two pages. Questions, comments, criticism, or requests can be directed Here More Cheat Sheets Here.
Copyright 2005 Peter Freitag (http://www.petefreitag.com/), All Rights Reserved. This document may be printed freely as long as this notice stays intact.
http://www.petefreitag.com/cheatsheets/postgresql/
Page 2 of 2