postgresql ► introduction most advanced opensource ordbms 1997 by university of california free...

Download PostgreSQL ► Introduction  Most Advanced Opensource ORDBMS  1997 by University of California  Free source code and open std

If you can't read please download the document

Upload: agnes-harvey

Post on 18-Jan-2018

223 views

Category:

Documents


0 download

DESCRIPTION

PostgreSQL Vs SQL Server

TRANSCRIPT

PostgreSQL Introduction Most Advanced Opensource ORDBMS 1997 by University of California Free source code and open std PSQL Features ORDBMS Complex SQL Queries, Multi user support, MVCC, Query optimization, Inheritance and arrays SQL Support SQL 99 ( or) SQL 3 Highly Extensible User defined operations, functions, access methods and data types Referential Integrity Flexible API -Python, Perl, PHP, C, C++ Procedural Languages Client Server Write Ahead Logging (WAL) PostgreSQL Vs SQL Server POSTGRESQLMYSQL ANSI SQL complianceCloser to ANSI SQL standard Follows some of the ANSI SQL standards PerformanceSlowerFaster Sub-selectsYesNo TransactionsYes Yes, however InnoDB table type must be used Database replicationYes Foreign key supportYesNo ViewsYesNo Stored proceduresYesNo TriggersYesNo UnionsYesNo Full joinsYesNo ConstraintsYesNo Windows supportYes Vacuum (cleanup)YesNo ODBCYes JDBCYes Different table typesNoYes Data Type Description box A geometric box, rectangle circle A circle defined by a point and a radius line A line defined by a starting point and an end point lseg A geometric line segment path A sequence of lines defined by points point A point defined by two coordinates polygon A polygon defined by a list of points PostgreSQL's Geometric Data Types Data Type Internal Size Description cidr12 bytes Stores valid Ipv4 network addresses inet12 bytes Stores IP addresses or network addresses macad dr 6 bytes Stores MAC addresses Working with Arrays One-Dimensional Arrays Multidimensional Arrays Example: CREATE TABLE parent (name_mother text, name_children text[2]); INSERT INTO parent VALUES ('Andrea', '{"Paul", "Lisa"}'); CREATE SEQUENCE ship_id START 200 INCREMENT Creates a new sequence in an existing database CREATE SEQUENCE CREATE UNIQUE INDEX employee_id_idx ON employees(id) Creates new index on a table column CREATE INDEX CREATE TABLE book;Creates a new table in an exiting database CREATE TABLE CREATE DATABASE booktown; Creates a new database in PostgreSQL CREATE DATABASE ExamplePurposeCommands PostgreSQL Commands UPDATE stock SET stock = stock + 1 WHERE isbn = ' ' ; Modifies the data in existing table records UPDATE INSERT INTO employees (id, last_name) VALUES (108, 'Williams'); Adds one or more new records into a table INSERT SELECT * FROM books WHERE id > 5000 ;Retrieves records from a table SELECT ExamplePurposeCommands CREATE VIEW h_publishers AS SELECT * FROM publishers WHERE name LIKE 'H% ; Creates a new view on an existing table CREATE VIEW CREATE TRIGGER sync_authors_booksBEFORE UPDATEON authorsFOR EACH ROWEXECUTE PROCEDURE sync_authors_and_books(); Creates a new trigger definition CREATE TRIGGER DROP TRIGGER sync_authors_books ON authors; Destroys an existing trigger definition DROP TRIGGER DROP TABLE employees; Destroys an existing table DROP TABLE DROP SEQUENCE shipments_ship_id_seq; Destroys an existing sequence generator DROP SEQUENCE DROP INDEX books_id_pkey, books_title_idx; Removes a column an index from an existing table DROP INDEX ExamplePurposeCommands DROP DATABASE testdb; Destroys an existing database DROP DATABASE DELETE FROM shipments WHERE customer_id = 142 AND ship_date < ' ' ; Removes existing records from a table DELETE REVOKE INSERT ON guest FROM books; Deny rights on a database object from a user. REVOKE GRANT ALL ON publishers TO manager; Grant rights on a database object to a user GRANT DROP USER jonathan; Removes an existing PostgrSQL user account DROP USER ALTER USER mark WITH PASSWORD 'ml0215em; Modifies an existing PostgreSQL user account ALTER USER ExamplePurposeCommands CREATE USER david WITH PASSWORD 'jw8s0F4' CREATEDB IN GROUP accounting VALID UNTIL 'Jan ' ; Adds a new PostgreSQL user account to the system CREATE USER DROP VIEW h_publishers; Destroys an existing table view DROP VIEW CREATE OPERATOR !# (PROCEDURE = is_zero, LEFTARG = integer, RIGHTARG = integer); Creates a new SQL operator within a database CREATE OPERATOR ExamplePurposeCommands CREATE FUNCTION example_call_handler () RETURNS opaqueAS'/usr/local/pgsql/li b/libexample.so' LANGUAGE 'C'; Creates a new language definition within a database CREATE LANGUAGE CREATE FUNCTION title(integer) RETURNS text AS 'SELECT title from books where id = $1'LANGUAGE 'sql'; Creates a new SQL function within a database CREATE FUNCTION UPDATE stock SET stock = stock + 1 WHERE isbn = ' '; Modifies the values of column data within a table UPDATE TRUNCATE TABLE temp_emp; Empties the contents of a table TRUNCATE ExamplePurposeCommands DELETE FROM shipments WHERE customer_id = 142AND ship_date < ' '; Deletes rows from a table DELETE CREATE TYPE zero (internallength = 16, input = zero_in, output = zero_out); Creates a new SQL data type within a database CREATE TYPE SELECT CURRENT_TIME AS the_time; Returns the current time CURRENT_TIME SELECT CURRENT_DATE AS today; Returns the current date CURRENT_DATE COPY publishers FROM '/tmp/publisher_data' ; Copies data between files and tables COPY ExamplePurposeCommands ALTER TABLE employees ADD COLUMN address text; Modifies table and column attributes ALTER TABLE BEGIN WORK; DELETE FROM publishers WHERE id < 100;ABORT WORK; Rolls back changes made during a transaction block ABORT BEGIN WORK; CREATE TABLE test (id integer, name text); COMMIT WORK; BEGIN - Starts a chained-mode transaction block. COMMIT -- Ends the current transaction block and finalizes changes made within it. BEGIN /COMMIT SELECT CURRENT_TIMESTAMP AS date_and_time; Returns the current date and time CURRENT_TIMESTAMP not available in SQL ExamplePurposeCommands SELECT * INTO TEMP TABLE old_empFROM employeesWHERE id < 105; Construct a new table from the results of a SELECT SELECT INTO SELECT CURRENT_USER AS myself; Returns the current database username CURRENT_USER Logical Operators The usual logical operators are available: AND OR NOT Comparison Operators Operator Description < less than > greater than = greater than or equal to = equal or != not equal Mathematical Functions and Operators String Functions and Operators Binary String Functions and Operators Pattern Matching LIKE string LIKE pattern [ESCAPE escape-character] string NOT LIKE pattern [ESCAPE escape- character] SIMILAR TO Regular Expressions string SIMILAR TO pattern [ESCAPE escape- character] string NOT SIMILAR TO pattern [ESCAPE escape-character] Data Type Formatting Functions Date/Time Functions and Operators Enum Support Functions Conditional Expressions CASE The SQL CASE expression is a generic conditional expression, similar to if/else statements in other programming languages: CASE WHEN condition THEN result [WHEN...] [ELSE result] END COALESCE COALESCE(value [,...]) NULLIF NULLIF(value1, value2) GREATEST and LEAST GREATEST(value [,...]) LEAST(value [,...]) Trigger CREATE OR REPLACE FUNCTION mytrigger() RETURNS trigger AS $BODY$ DECLARE BEGIN IF(TG_OP = 'INSERT')THEN END IF; IF(TG_OP = 'UPDATE') THEN END IF; IF TG_OP = 'DELETE' THEN END IF; END ; $BODY$ Geometric Functions and Operators Network Address Functions and Operators Text Search Functions and Operators XML Functions Sequence Manipulation Functions Array Functions and Operators Aggregate Functions Subquery Expressions Important link lpgsql-control-structures.htmllpgsql-control-structures.htmllpgsql-control-structures.html