├── .gitignore ├── config.cfg ├── refreshIndex.sh ├── index-template.json ├── river.json ├── setupBooktown.py ├── switchAliases.py ├── README.md ├── setNextIndexNumberForAlias.py └── booktown.sql /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | *.txt 3 | -------------------------------------------------------------------------------- /config.cfg: -------------------------------------------------------------------------------- 1 | [Elasticsearch] 2 | server=localhost:9200 3 | alias=booktown -------------------------------------------------------------------------------- /refreshIndex.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | echo "set new index name in river" 3 | python reindxBooktown.py 4 | erestart 5 | python switchAliases.py -------------------------------------------------------------------------------- /index-template.json: -------------------------------------------------------------------------------- 1 | { 2 | "template": "booktown*", 3 | "mappings": { 4 | "books": { 5 | "properties": { 6 | "Books": { 7 | "properties": { 8 | "id": { 9 | "type": "long" 10 | }, 11 | "subject_id": { 12 | "type": "long" 13 | }, 14 | "title": { 15 | "type": "string" 16 | } 17 | } 18 | }, 19 | "first_name": { 20 | "type": "string" 21 | }, 22 | "last_name": { 23 | "type": "string" 24 | } 25 | } 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /river.json: -------------------------------------------------------------------------------- 1 | { 2 | "type" : "jdbc", 3 | "jdbc" : { 4 | "driver" : "org.postgresql.Driver", 5 | "url" : "jdbc:postgresql://localhost:5432/booktown", 6 | "user" : "postgres", 7 | "password" : "postgres", 8 | "index" : "booktown_1", 9 | "schedule": "30 * * * * ?", 10 | "poolsize" : 2, 11 | "type" : "books", 12 | "sql" : "SELECT authors.id as _id, authors.last_name, authors.first_name, books.id as \"Books.id\", books.title as \"Books.title\", books.subject_id as \"Books.subject_id\" FROM public.authors left join public.books on books.author_id = authors.id order by authors.id " 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /setupBooktown.py: -------------------------------------------------------------------------------- 1 | ## SETUP SCRIPT FOR Booktown ELASTICSEARCH 2 | import elasticsearch 3 | import logging 4 | import os 5 | import json 6 | import sys 7 | import ConfigParser 8 | 9 | config = ConfigParser.RawConfigParser() 10 | config.read('config.cfg') 11 | es_server = config.get('Elasticsearch','server') 12 | if es_server == '': 13 | print "Please tell me the hostname of your elasticsearch server" 14 | sys.exit(2) 15 | es = elasticsearch.Elasticsearch(es_server) 16 | es_alias = config.get('Elasticsearch','alias') 17 | es_index = "{}_{}".format(es_alias,"1") 18 | 19 | from elasticsearch.transport import Transport 20 | def main(): 21 | logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s', filename='reindx.log') 22 | from os import listdir 23 | from os.path import isfile, join 24 | if es.indices.exists(es_index) == True: 25 | es.indices.delete(es_index) 26 | es.indices.create(es_index) 27 | mapping = json.loads(open("index-template.json", "r").read()) 28 | es.indices.put_template(body=mapping,name=es_alias + 'template') 29 | es.indices.put_alias(index=es_index,name=es_alias) 30 | from elasticsearch.transport import Transport 31 | river = json.loads(open("river.json", "r").read()) 32 | es.transport.perform_request('PUT', '/_river/' + es_alias + '/_meta', body=river ) 33 | if __name__ == '__main__': 34 | main() 35 | -------------------------------------------------------------------------------- /switchAliases.py: -------------------------------------------------------------------------------- 1 | 2 | # This script reads a "current index number" from file 3 | #setting the alias "es_alias" to point to the newly created index, removing the old pointer, and deleting the old index. 4 | import elasticsearch 5 | import logging 6 | import os 7 | import json 8 | import sys 9 | import ConfigParser 10 | 11 | #es_server = 'http://192.168.125.116:9200/' 12 | #es_server = 'http://localhost:9200/' 13 | #es_server = 'http://80.91.34.90:9200/' 14 | config = ConfigParser.RawConfigParser() 15 | config.read('config.cfg') 16 | es_server = config.get('Elasticsearch','server') 17 | logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s', filename='reindx.log') 18 | logger = logging.getLogger('newAlias') 19 | if es_server == '': 20 | print "Please supply servername" 21 | logger.error('No Elasticsearch server in config') 22 | exit() 23 | file = open('nextIndexNumber.txt','r') 24 | nextNumber = file.read() 25 | es_indexNumber = int(nextNumber) 26 | if es_indexNumber == '': 27 | print "cannot procedd without indexnumber" 28 | logger.info("no new indexnumber given. aborting") 29 | exit() 30 | def main(): 31 | from os import listdir 32 | from os.path import isfile, join 33 | es = elasticsearch.Elasticsearch(es_server) 34 | es_alias = config.get('Elasticsearch','alias') 35 | es_index = "{}_{}".format(es_alias, es_indexNumber) 36 | oldIndex = int(es_indexNumber) - 1 37 | es_old_index = "{}_{}".format(es_alias, oldIndex) 38 | logger.info("will remove old index {} and set new index {} for alias {}".format(es_old_index, es_index, es_alias)) 39 | actions = {'actions': [{'remove': {'index': es_old_index, 'alias':es_alias} }, {'add': {'index': es_index, 'alias':es_alias}}]} 40 | 41 | es.indices.update_aliases(body=json.dumps(actions)) 42 | es.indices.delete(es_old_index) 43 | if __name__ == '__main__': 44 | main() 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #Elasticsearch river-jdbc demo 2 | ##Prerequisites: 3 | 4 | Download and install 5 | 6 | - [elasticsearch 1.0.0](http://www.elasticsearch.org/overview/elkdownloads/) 7 | 8 | - [postgresql](http://www.postgresql.org/download/) 9 | 10 | Latest version of postgres jdbc driver 11 | http://www.postgresql.org/download/ 12 | 13 | ## Setup postgres 14 | Download [booktown.sql](http://www.commandprompt.com/ppbook/booktown.sql) to install the BookTown database 15 | 16 | 17 | psql -u postgres -f booktown.sql 18 | 19 | 20 | ## Setup Elasticsearch 21 | Install the [river-jdbc elasticsearch plugin](https://github.com/jprante/elasticsearch-river-jdbc) 22 | 23 | 24 | ./bin/plugin --install river-jdbc --url http://bit.ly/1jyXrR9 (ES 1.0.0) 25 | 26 | 27 | ### Download postgres jdbc driver jar 28 | [http://jdbc.postgresql.org/download.html](http://jdbc.postgresql.org/download.html) 29 | (Recommended version is [JDBC 41](http://jdbc.postgresql.org/download/postgresql-9.3-1100.jdbc41.jar) 30 | ) 31 | Copy the postgres.****.jar file into the `/plugins/river-jdbc` folder of your elasticsearch installation. 32 | 33 | 34 | ##Elasticsearch commandoes: 35 | All the Elasticsearch commandoes you need to use to follow this demo are available at 36 | [http://sense.qbox.io/gist/d10ac6949d7574a5f0acc94b309b9d3ab314b13e](http://sense.qbox.io/gist/d10ac6949d7574a5f0acc94b309b9d3ab314b13e). 37 | 38 | [An introduction to using the Sense plugin](https://www.found.no/foundation/Sense-Elasticsearch-interface/) 39 | 40 | [http://sense.qbox.io](http://sense.qbox.io) provide a hosted Sense experience, something like Gist for Elasticsearch. 41 | 42 | restart elasticsearch 43 | loaded [river-jdbc] should occur in log 44 | 45 | 46 | Put river 47 | "success [15 items]" 48 | 49 | 50 | select books.id as _id, title, author_id as 'Author.Id', subject_id as 'Subject.Id', last_name as 'Author.LastName', first_name as 'Author.FirstName', subject as 'Subject.Subject', location as 'Subject.Location' from books left join authors on authors.id = books.author_id left join subjects on books.subject_id = subjects.id 51 | 52 | select books.id as _id, title, author_id , subject_id , last_name , first_name , subject , location from books left join authors on authors.id = books.author_id left join subjects on books.subject_id = subjects.id 53 | 54 | https://github.com/jprante/elasticsearch-river-jdbc/wiki/Structured-Objects 55 | -------------------------------------------------------------------------------- /setNextIndexNumberForAlias.py: -------------------------------------------------------------------------------- 1 | ## Index Alias SCRIPT 2 | # This is part of a set of three scripts that enable reindexing content into river-jdbc 3 | # This script creates a new index for the river-jdbc to index into 4 | # Indexes are referenced by an alias, and the alias is pointing to 5 | # The new index number is stored in file "nextIndexNumber.txt" 6 | # Another script runs after elasticsearch is restarted, setting the alias "es_alias" to point to the newly created index, 7 | # removing the old pointer, and deleting the old index. 8 | import elasticsearch 9 | import logging 10 | import os 11 | import json 12 | import sys 13 | import re 14 | import ConfigParser 15 | config = ConfigParser.RawConfigParser() 16 | config.read('config.cfg') 17 | es_server = config.get('Elasticsearch','server') 18 | if es_server == '': 19 | print "Please supply servername" 20 | sys.exit(2) 21 | print es_server 22 | es = elasticsearch.Elasticsearch(es_server) 23 | 24 | es_alias = config.get('Elasticsearch','alias') 25 | es_index = "{}_{}".format(es_alias,"2") 26 | es_old_index = "{}_{}".format(es_alias,"1") 27 | 28 | from elasticsearch.transport import Transport 29 | def main(): 30 | logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s', filename='reindx.log') 31 | from os import listdir 32 | from os.path import isfile, join 33 | logger = logging.getLogger('newAlias') 34 | existingAlias = es.cat.aliases(es_alias) 35 | if existingAlias == '': 36 | logger.error("no Existing alias found") 37 | sys.exit(2) 38 | aliasMatch = re.search(r"(\d+)", existingAlias) 39 | if aliasMatch == None: 40 | logger.error("no matching index definition found for alias {}".format(existingAlias) ) 41 | sys.exit(2) 42 | es_old_index = existingAlias.split()[1] 43 | logger.info("found old index {}".format(es_old_index)) 44 | groupResult = aliasMatch.groups() 45 | aliasNumber = int(groupResult[0]) 46 | aliasNumber += 1 47 | es_index = "{}_{}".format(es_alias, aliasNumber) 48 | logger.info("will create new index {}".format(es_index)) 49 | es.indices.create(es_index) 50 | river = json.loads(open("river.json", "r").read()) 51 | logger.info("got the old river from river-jdbc {}".format(river['jdbc']['index']) 52 | river['jdbc']['index'] = es_index 53 | print river 54 | es.transport.perform_request('PUT', '/_river/' + es_alias + '/_meta', body=river) 55 | # Write out the number of the index index. 56 | with open('nextIndexNumber.txt', 'wb') as fh: 57 | fh.write(str(aliasNumber)+'\n') 58 | if __name__ == '__main__': 59 | main() 60 | -------------------------------------------------------------------------------- /booktown.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- Selected TOC Entries: 3 | -- 4 | -- 5 | -- TOC Entry ID 1 (OID 0) 6 | -- 7 | -- Name: booktown Type: DATABASE Owner: postgres 8 | -- 9 | 10 | Create Database "booktown"; 11 | 12 | \connect booktown postgres 13 | -- 14 | -- TOC Entry ID 2 (OID 2991542) 15 | -- 16 | -- Name: DATABASE "booktown" Type: COMMENT Owner: 17 | -- 18 | 19 | COMMENT ON DATABASE "booktown" IS 'The Book Town Database.'; 20 | 21 | -- 22 | -- TOC Entry ID 33 (OID 3629264) 23 | -- 24 | -- Name: books Type: TABLE Owner: manager 25 | -- 26 | 27 | CREATE TABLE "books" ( 28 | "id" integer NOT NULL, 29 | "title" text NOT NULL, 30 | "author_id" integer, 31 | "subject_id" integer, 32 | Constraint "books_id_pkey" Primary Key ("id") 33 | ); 34 | 35 | -- 36 | -- TOC Entry ID 47 (OID 2991733) 37 | -- 38 | -- Name: "plpgsql_call_handler" () Type: FUNCTION Owner: postgres 39 | -- 40 | 41 | CREATE FUNCTION "plpgsql_call_handler" () RETURNS opaque AS '/usr/local/pgsql/lib/plpgsql.so', 'plpgsql_call_handler' LANGUAGE 'C'; 42 | 43 | -- 44 | -- TOC Entry ID 48 (OID 2991734) 45 | -- 46 | -- Name: plpgsql Type: PROCEDURAL LANGUAGE Owner: 47 | -- 48 | 49 | CREATE TRUSTED PROCEDURAL LANGUAGE 'plpgsql' HANDLER "plpgsql_call_handler" LANCOMPILER 'PL/pgSQL'; 50 | 51 | -- 52 | -- TOC Entry ID 51 (OID 2991735) 53 | -- 54 | -- Name: "audit_bk" (integer) Type: FUNCTION Owner: postgres 55 | -- 56 | 57 | CREATE FUNCTION "audit_bk" (integer) RETURNS integer AS ' 58 | DECLARE 59 | key ALIAS FOR $1; 60 | table_data inventory%ROWTYPE; 61 | BEGIN 62 | INSERT INTO inventory_audit SELECT table_data WHERE sort_key=key; 63 | 64 | IF NOT FOUND THEN 65 | RAISE EXCEPTION ''View'' || key || '' not found ''; 66 | END IF; 67 | 68 | return 1; 69 | end; 70 | ' LANGUAGE 'plpgsql'; 71 | 72 | -- 73 | -- TOC Entry ID 52 (OID 2991736) 74 | -- 75 | -- Name: "audit" (integer) Type: FUNCTION Owner: postgres 76 | -- 77 | 78 | CREATE FUNCTION "audit" (integer) RETURNS integer AS ' 79 | DECLARE 80 | key ALIAS FOR $1; 81 | table_data inventory%ROWTYPE; 82 | BEGIN 83 | INSERT INTO inventory_audit SELECT table_data WHERE sort_key=key; 84 | 85 | IF NOT FOUND THEN 86 | RAISE EXCEPTION ''View'' || key || '' not found ''; 87 | END IF; 88 | 89 | return 1; 90 | end; 91 | ' LANGUAGE 'plpgsql'; 92 | 93 | -- 94 | -- TOC Entry ID 53 (OID 2991737) 95 | -- 96 | -- Name: "auditbk" () Type: FUNCTION Owner: postgres 97 | -- 98 | 99 | CREATE FUNCTION "auditbk" () RETURNS integer AS ' 100 | DECLARE 101 | key ALIAS FOR $1; 102 | table_data inventory%ROWTYPE; 103 | BEGIN 104 | INSERT INTO inventory_audit SELECT table_data WHERE sort_key=key; 105 | 106 | IF NOT FOUND THEN 107 | RAISE EXCEPTION ''View'' || key || '' not found ''; 108 | END IF; 109 | 110 | return 1; 111 | end; 112 | ' LANGUAGE 'plpgsql'; 113 | 114 | -- 115 | -- TOC Entry ID 54 (OID 2991738) 116 | -- 117 | -- Name: "audit_bk1" () Type: FUNCTION Owner: postgres 118 | -- 119 | 120 | CREATE FUNCTION "audit_bk1" () RETURNS opaque AS ' 121 | DECLARE 122 | key ALIAS FOR $1; 123 | table_data inventory%ROWTYPE; 124 | BEGIN 125 | INSERT INTO inventory_audit SELECT table_data WHERE sort_key=key; 126 | 127 | IF NOT FOUND THEN 128 | RAISE EXCEPTION ''View'' || key || '' not found ''; 129 | END IF; 130 | 131 | return 1; 132 | end; 133 | ' LANGUAGE 'plpgsql'; 134 | 135 | -- 136 | -- TOC Entry ID 73 (OID 2991835) 137 | -- 138 | -- Name: "test_check_a_id" () Type: FUNCTION Owner: example 139 | -- 140 | 141 | CREATE FUNCTION "test_check_a_id" () RETURNS opaque AS ' 142 | BEGIN 143 | -- checks to make sure the author id 144 | -- inserted is not left blank or less than 100 145 | 146 | IF NEW.a_id ISNULL THEN 147 | RAISE EXCEPTION 148 | ''The author id cannot be left blank!''; 149 | ELSE 150 | IF NEW.a_id < 100 THEN 151 | RAISE EXCEPTION 152 | ''Please insert a valid author id.''; 153 | ELSE 154 | RETURN NEW; 155 | END IF; 156 | END IF; 157 | END; 158 | ' LANGUAGE 'plpgsql'; 159 | 160 | -- 161 | -- TOC Entry ID 66 (OID 2992619) 162 | -- 163 | -- Name: "audit_test" () Type: FUNCTION Owner: example 164 | -- 165 | 166 | CREATE FUNCTION "audit_test" () RETURNS opaque AS ' 167 | BEGIN 168 | 169 | IF TG_OP = ''INSERT'' OR TG_OP = ''UPDATE'' THEN 170 | 171 | NEW.user_aud := current_user; 172 | NEW.mod_time := ''NOW''; 173 | 174 | INSERT INTO inventory_audit SELECT * FROM inventory WHERE prod_id=NEW.prod_id; 175 | 176 | RETURN NEW; 177 | 178 | ELSE if TG_OP = ''DELETE'' THEN 179 | INSERT INTO inventory_audit SELECT *, current_user, ''NOW'' FROM inventory WHERE prod_id=OLD.prod_id; 180 | 181 | RETURN OLD; 182 | END IF; 183 | END IF; 184 | END; 185 | ' LANGUAGE 'plpgsql'; 186 | 187 | -- 188 | -- TOC Entry ID 67 (OID 3000878) 189 | -- 190 | -- Name: "first" () Type: FUNCTION Owner: example 191 | -- 192 | 193 | CREATE FUNCTION "first" () RETURNS integer AS ' 194 | DecLarE 195 | oNe IntEgER := 1; 196 | bEGiN 197 | ReTUrn oNE; 198 | eNd; 199 | ' LANGUAGE 'plpgsql'; 200 | 201 | -- 202 | -- TOC Entry ID 68 (OID 3000881) 203 | -- 204 | -- Name: "test" (integer) Type: FUNCTION Owner: example 205 | -- 206 | 207 | CREATE FUNCTION "test" (integer) RETURNS integer AS ' 208 | 209 | DECLARE 210 | -- defines the variable as ALIAS 211 | variable ALIAS FOR $1; 212 | BEGIN 213 | -- displays the variable after multiplying it by two 214 | return variable * 2.0; 215 | END; 216 | ' LANGUAGE 'plpgsql'; 217 | 218 | -- 219 | -- TOC Entry ID 69 (OID 3000991) 220 | -- 221 | -- Name: "you_me" (integer) Type: FUNCTION Owner: example 222 | -- 223 | 224 | CREATE FUNCTION "you_me" (integer) RETURNS integer AS ' 225 | DECLARE 226 | RENAME $1 TO user_no; 227 | --you INTEGER := 5; 228 | BEGIN 229 | return user_no; 230 | END;' LANGUAGE 'plpgsql'; 231 | 232 | -- 233 | -- TOC Entry ID 62 (OID 3001136) 234 | -- 235 | -- Name: "count_by_two" (integer) Type: FUNCTION Owner: example 236 | -- 237 | 238 | CREATE FUNCTION "count_by_two" (integer) RETURNS integer AS ' 239 | DECLARE 240 | userNum ALIAS FOR $1; 241 | i integer; 242 | BEGIN 243 | i := 1; 244 | WHILE userNum[1] < 20 LOOP 245 | i = i+1; 246 | return userNum; 247 | END LOOP; 248 | 249 | END; 250 | ' LANGUAGE 'plpgsql'; 251 | 252 | -- 253 | -- TOC Entry ID 63 (OID 3001139) 254 | -- 255 | -- Name: "me" () Type: FUNCTION Owner: example 256 | -- 257 | 258 | CREATE FUNCTION "me" () RETURNS text AS ' 259 | DECLARE 260 | you text := ''testing''; 261 | RENAME you to me; 262 | BEGIN 263 | return me; 264 | END;' LANGUAGE 'plpgsql'; 265 | 266 | -- 267 | -- TOC Entry ID 64 (OID 3001149) 268 | -- 269 | -- Name: "display_cust" (integer) Type: FUNCTION Owner: example 270 | -- 271 | 272 | CREATE FUNCTION "display_cust" (integer) RETURNS text AS ' 273 | DECLARE 274 | -- declares an alias name for input 275 | cust_num ALIAS FOR $1; 276 | 277 | -- declares a row type 278 | cust_info customer%ROWTYPE; 279 | BEGIN 280 | -- puts information into the newly declared rowtype 281 | SELECT into cust_info * 282 | FROM customer 283 | WHERE cust_id=cust_num; 284 | 285 | -- displays the customer lastname 286 | -- extracted from the rowtype 287 | return cust_info.lastname; 288 | END; 289 | ' LANGUAGE 'plpgsql'; 290 | 291 | -- 292 | -- TOC Entry ID 65 (OID 3001151) 293 | -- 294 | -- Name: "mixed" () Type: FUNCTION Owner: example 295 | -- 296 | 297 | CREATE FUNCTION "mixed" () RETURNS integer AS ' 298 | DecLarE 299 | --assigns 1 to the oNe variable 300 | oNe IntEgER 301 | := 1; 302 | 303 | bEGiN 304 | 305 | --displays the value of oNe 306 | ReTUrn oNe; 307 | eNd; 308 | ' LANGUAGE 'plpgsql'; 309 | 310 | -- 311 | -- TOC Entry ID 12 (OID 3117548) 312 | -- 313 | -- Name: publishers Type: TABLE Owner: postgres 314 | -- 315 | 316 | CREATE TABLE "publishers" ( 317 | "id" integer NOT NULL, 318 | "name" text, 319 | "address" text, 320 | Constraint "publishers_pkey" Primary Key ("id") 321 | ); 322 | 323 | -- 324 | -- TOC Entry ID 55 (OID 3117729) 325 | -- 326 | -- Name: "compound_word" (text,text) Type: FUNCTION Owner: example 327 | -- 328 | 329 | CREATE FUNCTION "compound_word" (text,text) RETURNS text AS ' 330 | DECLARE 331 | -- defines an alias name for the two input values 332 | word1 ALIAS FOR $1; 333 | word2 ALIAS FOR $2; 334 | BEGIN 335 | -- displays the resulting joined words 336 | RETURN word1 || word2; 337 | END; 338 | ' LANGUAGE 'plpgsql'; 339 | 340 | -- 341 | -- TOC Entry ID 56 (OID 3117787) 342 | -- 343 | -- Name: "givename" () Type: FUNCTION Owner: example 344 | -- 345 | 346 | CREATE FUNCTION "givename" () RETURNS opaque AS ' 347 | DECLARE 348 | tablename text; 349 | BEGIN 350 | 351 | tablename = TG_RELNAME; 352 | INSERT INTO INVENTORY values (123, tablename); 353 | return old; 354 | END; 355 | ' LANGUAGE 'plpgsql'; 356 | 357 | -- 358 | -- TOC Entry ID 14 (OID 3389594) 359 | -- 360 | -- Name: authors Type: TABLE Owner: manager 361 | -- 362 | 363 | CREATE TABLE "authors" ( 364 | "id" integer NOT NULL, 365 | "last_name" text, 366 | "first_name" text, 367 | Constraint "authors_pkey" Primary Key ("id") 368 | ); 369 | 370 | -- 371 | -- TOC Entry ID 15 (OID 3389632) 372 | -- 373 | -- Name: states Type: TABLE Owner: postgres 374 | -- 375 | 376 | CREATE TABLE "states" ( 377 | "id" integer NOT NULL, 378 | "name" text, 379 | "abbreviation" character(2), 380 | Constraint "state_pkey" Primary Key ("id") 381 | ); 382 | 383 | -- 384 | -- TOC Entry ID 16 (OID 3389702) 385 | -- 386 | -- Name: my_list Type: TABLE Owner: postgres 387 | -- 388 | 389 | CREATE TABLE "my_list" ( 390 | "todos" text 391 | ); 392 | 393 | -- 394 | -- TOC Entry ID 17 (OID 3390348) 395 | -- 396 | -- Name: stock Type: TABLE Owner: postgres 397 | -- 398 | 399 | CREATE TABLE "stock" ( 400 | "isbn" text NOT NULL, 401 | "cost" numeric(5,2), 402 | "retail" numeric(5,2), 403 | "stock" integer, 404 | Constraint "stock_pkey" Primary Key ("isbn") 405 | ); 406 | 407 | -- 408 | -- TOC Entry ID 4 (OID 3390416) 409 | -- 410 | -- Name: subject_ids Type: SEQUENCE Owner: postgres 411 | -- 412 | 413 | CREATE SEQUENCE "subject_ids" start 0 increment 1 maxvalue 2147483647 minvalue 0 cache 1 ; 414 | 415 | -- 416 | -- TOC Entry ID 19 (OID 3390653) 417 | -- 418 | -- Name: numeric_values Type: TABLE Owner: postgres 419 | -- 420 | 421 | CREATE TABLE "numeric_values" ( 422 | "num" numeric(30,6) 423 | ); 424 | 425 | -- 426 | -- TOC Entry ID 20 (OID 3390866) 427 | -- 428 | -- Name: daily_inventory Type: TABLE Owner: postgres 429 | -- 430 | 431 | CREATE TABLE "daily_inventory" ( 432 | "isbn" text, 433 | "is_stocked" boolean 434 | ); 435 | 436 | -- 437 | -- TOC Entry ID 21 (OID 3391084) 438 | -- 439 | -- Name: money_example Type: TABLE Owner: postgres 440 | -- 441 | 442 | CREATE TABLE "money_example" ( 443 | "money_cash" money, 444 | "numeric_cash" numeric(6,2) 445 | ); 446 | 447 | -- 448 | -- TOC Entry ID 22 (OID 3391184) 449 | -- 450 | -- Name: shipments Type: TABLE Owner: postgres 451 | -- 452 | 453 | CREATE TABLE "shipments" ( 454 | "id" integer DEFAULT nextval('"shipments_ship_id_seq"'::text) NOT NULL, 455 | "customer_id" integer, 456 | "isbn" text, 457 | "ship_date" timestamp with time zone 458 | ); 459 | 460 | -- 461 | -- TOC Entry ID 24 (OID 3391454) 462 | -- 463 | -- Name: customers Type: TABLE Owner: manager 464 | -- 465 | 466 | CREATE TABLE "customers" ( 467 | "id" integer NOT NULL, 468 | "last_name" text, 469 | "first_name" text, 470 | Constraint "customers_pkey" Primary Key ("id") 471 | ); 472 | 473 | -- 474 | -- TOC Entry ID 6 (OID 3574018) 475 | -- 476 | -- Name: book_ids Type: SEQUENCE Owner: postgres 477 | -- 478 | 479 | CREATE SEQUENCE "book_ids" start 0 increment 1 maxvalue 2147483647 minvalue 0 cache 1 ; 480 | 481 | -- 482 | -- TOC Entry ID 26 (OID 3574043) 483 | -- 484 | -- Name: book_queue Type: TABLE Owner: postgres 485 | -- 486 | 487 | CREATE TABLE "book_queue" ( 488 | "title" text NOT NULL, 489 | "author_id" integer, 490 | "subject_id" integer, 491 | "approved" boolean 492 | ); 493 | 494 | -- 495 | -- TOC Entry ID 78 (OID 3574403) 496 | -- 497 | -- Name: "title" (integer) Type: FUNCTION Owner: postgres 498 | -- 499 | 500 | CREATE FUNCTION "title" (integer) RETURNS text AS 'SELECT title from books where id = $1' LANGUAGE 'sql'; 501 | 502 | -- 503 | -- TOC Entry ID 27 (OID 3574983) 504 | -- 505 | -- Name: stock_backup Type: TABLE Owner: postgres 506 | -- 507 | 508 | CREATE TABLE "stock_backup" ( 509 | "isbn" text, 510 | "cost" numeric(5,2), 511 | "retail" numeric(5,2), 512 | "stock" integer 513 | ); 514 | 515 | -- 516 | -- TOC Entry ID 89 (OID 3625934) 517 | -- 518 | -- Name: "double_price" (double precision) Type: FUNCTION Owner: postgres 519 | -- 520 | 521 | CREATE FUNCTION "double_price" (double precision) RETURNS double precision AS ' 522 | DECLARE 523 | BEGIN 524 | return $1 * 2; 525 | END; 526 | ' LANGUAGE 'plpgsql'; 527 | 528 | -- 529 | -- TOC Entry ID 90 (OID 3625935) 530 | -- 531 | -- Name: "triple_price" (double precision) Type: FUNCTION Owner: postgres 532 | -- 533 | 534 | CREATE FUNCTION "triple_price" (double precision) RETURNS double precision AS ' 535 | DECLARE 536 | -- Declare input_price as an alias for the 537 | -- argument variable normally referenced with 538 | -- the $1 identifier. 539 | input_price ALIAS FOR $1; 540 | 541 | BEGIN 542 | -- Return the input price multiplied by three. 543 | RETURN input_price * 3; 544 | END; 545 | ' LANGUAGE 'plpgsql'; 546 | 547 | -- 548 | -- TOC Entry ID 87 (OID 3625944) 549 | -- 550 | -- Name: "stock_amount" (integer,integer) Type: FUNCTION Owner: postgres 551 | -- 552 | 553 | CREATE FUNCTION "stock_amount" (integer,integer) RETURNS integer AS ' 554 | DECLARE 555 | -- Declare aliases for function arguments. 556 | b_id ALIAS FOR $1; 557 | b_edition ALIAS FOR $2; 558 | -- Declare variable to store the ISBN number. 559 | b_isbn TEXT; 560 | -- Declare variable to store the stock amount. 561 | stock_amount INTEGER; 562 | BEGIN 563 | -- This SELECT INTO statement retrieves the ISBN 564 | -- number of the row in the editions table that had 565 | -- both the book ID number and edition number that 566 | -- were provided as function arguments. 567 | SELECT INTO b_isbn isbn FROM editions WHERE 568 | book_id = b_id AND edition = b_edition; 569 | 570 | -- Check to see if the ISBN number retrieved 571 | -- is NULL. This will happen if there is not an 572 | -- existing book with both the ID number and edition 573 | -- number specified in the function arguments. 574 | -- If the ISBN is null, the function returns a 575 | -- value of -1 and ends. 576 | IF b_isbn IS NULL THEN 577 | RETURN -1; 578 | END IF; 579 | 580 | -- Retrieve the amount of books available from the 581 | -- stock table and record the number in the 582 | -- stock_amount variable. 583 | SELECT INTO stock_amount stock FROM stock WHERE isbn = b_isbn; 584 | 585 | -- Return the amount of books available. 586 | RETURN stock_amount; 587 | END; 588 | ' LANGUAGE 'plpgsql'; 589 | 590 | -- 591 | -- TOC Entry ID 86 (OID 3625946) 592 | -- 593 | -- Name: "in_stock" (integer,integer) Type: FUNCTION Owner: postgres 594 | -- 595 | 596 | CREATE FUNCTION "in_stock" (integer,integer) RETURNS boolean AS ' 597 | DECLARE 598 | b_id ALIAS FOR $1; 599 | b_edition ALIAS FOR $2; 600 | b_isbn TEXT; 601 | stock_amount INTEGER; 602 | BEGIN 603 | -- This SELECT INTO statement retrieves the ISBN 604 | -- number of the row in the editions table that had 605 | -- both the book ID number and edition number that 606 | -- were provided as function arguments. 607 | SELECT INTO b_isbn isbn FROM editions WHERE 608 | book_id = b_id AND edition = b_edition; 609 | 610 | -- Check to see if the ISBN number retrieved 611 | -- is NULL. This will happen if there is not an 612 | -- existing book with both the ID number and edition 613 | -- number specified in the function arguments. 614 | -- If the ISBN is null, the function returns a 615 | -- FALSE value and ends. 616 | IF b_isbn IS NULL THEN 617 | RETURN FALSE; 618 | END IF; 619 | 620 | -- Retrieve the amount of books available from the 621 | -- stock table and record the number in the 622 | -- stock_amount variable. 623 | SELECT INTO stock_amount stock FROM stock WHERE isbn = b_isbn; 624 | 625 | -- Use an IF/THEN/ELSE check to see if the amount 626 | -- of books available is less than, or equal to 0. 627 | -- If so, return FALSE. If not, return TRUE. 628 | IF stock_amount <= 0 THEN 629 | RETURN FALSE; 630 | ELSE 631 | RETURN TRUE; 632 | END IF; 633 | END; 634 | ' LANGUAGE 'plpgsql'; 635 | 636 | -- 637 | -- TOC Entry ID 82 (OID 3626013) 638 | -- 639 | -- Name: "extract_all_titles" () Type: FUNCTION Owner: postgres 640 | -- 641 | 642 | CREATE FUNCTION "extract_all_titles" () RETURNS text AS ' 643 | DECLARE 644 | sub_id INTEGER; 645 | text_output TEXT = '' ''; 646 | sub_title TEXT; 647 | row_data books%ROWTYPE; 648 | BEGIN 649 | FOR i IN 0..15 LOOP 650 | SELECT INTO sub_title subject FROM subjects WHERE id = i; 651 | text_output = text_output || '' 652 | '' || sub_title || '': 653 | ''; 654 | 655 | FOR row_data IN SELECT * FROM books 656 | WHERE subject_id = i LOOP 657 | 658 | IF NOT FOUND THEN 659 | text_output := text_output || ''None. 660 | ''; 661 | ELSE 662 | text_output := text_output || row_data.title || '' 663 | ''; 664 | END IF; 665 | 666 | END LOOP; 667 | END LOOP; 668 | RETURN text_output; 669 | END; 670 | ' LANGUAGE 'plpgsql'; 671 | 672 | -- 673 | -- TOC Entry ID 79 (OID 3626052) 674 | -- 675 | -- Name: "books_by_subject" (text) Type: FUNCTION Owner: postgres 676 | -- 677 | 678 | CREATE FUNCTION "books_by_subject" (text) RETURNS text AS ' 679 | DECLARE 680 | sub_title ALIAS FOR $1; 681 | sub_id INTEGER; 682 | found_text TEXT :=''''; 683 | BEGIN 684 | SELECT INTO sub_id id FROM subjects WHERE subject = sub_title; 685 | RAISE NOTICE ''sub_id = %'',sub_id; 686 | IF sub_title = ''all'' THEN 687 | found_text := extract_all_titles(); 688 | RETURN found_text; 689 | ELSE IF sub_id >= 0 THEN 690 | found_text := extract_title(sub_id); 691 | RETURN '' 692 | '' || sub_title || '': 693 | '' || found_text; 694 | END IF; 695 | END IF; 696 | RETURN ''Subject not found.''; 697 | END; 698 | ' LANGUAGE 'plpgsql'; 699 | 700 | -- 701 | -- TOC Entry ID 81 (OID 3626590) 702 | -- 703 | -- Name: "add_two_loop" (integer,integer) Type: FUNCTION Owner: postgres 704 | -- 705 | 706 | CREATE FUNCTION "add_two_loop" (integer,integer) RETURNS integer AS ' 707 | DECLARE 708 | 709 | -- Declare aliases for function arguments. 710 | 711 | low_number ALIAS FOR $1; 712 | high_number ALIAS FOR $2; 713 | 714 | -- Declare a variable to hold the result. 715 | 716 | result INTEGER = 0; 717 | 718 | BEGIN 719 | 720 | WHILE result != high_number LOOP 721 | result := result + 1; 722 | END LOOP; 723 | 724 | RETURN result; 725 | END; 726 | ' LANGUAGE 'plpgsql'; 727 | 728 | -- 729 | -- TOC Entry ID 92 (OID 3627916) 730 | -- 731 | -- Name: "extract_all_titles2" () Type: FUNCTION Owner: postgres 732 | -- 733 | 734 | CREATE FUNCTION "extract_all_titles2" () RETURNS text AS ' 735 | DECLARE 736 | sub_id INTEGER; 737 | text_output TEXT = '' ''; 738 | sub_title TEXT; 739 | row_data books%ROWTYPE; 740 | BEGIN 741 | FOR i IN 0..15 LOOP 742 | SELECT INTO sub_title subject FROM subjects WHERE id = i; 743 | text_output = text_output || '' 744 | '' || sub_title || '': 745 | ''; 746 | 747 | FOR row_data IN SELECT * FROM books 748 | WHERE subject_id = i LOOP 749 | 750 | text_output := text_output || row_data.title || '' 751 | ''; 752 | 753 | END LOOP; 754 | END LOOP; 755 | RETURN text_output; 756 | END; 757 | ' LANGUAGE 'plpgsql'; 758 | 759 | -- 760 | -- TOC Entry ID 94 (OID 3627974) 761 | -- 762 | -- Name: "extract_title" (integer) Type: FUNCTION Owner: postgres 763 | -- 764 | 765 | CREATE FUNCTION "extract_title" (integer) RETURNS text AS ' 766 | DECLARE 767 | sub_id ALIAS FOR $1; 768 | text_output TEXT :='' 769 | ''; 770 | row_data RECORD; 771 | BEGIN 772 | FOR row_data IN SELECT * FROM books 773 | WHERE subject_id = sub_id ORDER BY title LOOP 774 | text_output := text_output || row_data.title || '' 775 | ''; 776 | END LOOP; 777 | RETURN text_output; 778 | END; 779 | ' LANGUAGE 'plpgsql'; 780 | 781 | -- 782 | -- TOC Entry ID 95 (OID 3628021) 783 | -- 784 | -- Name: "raise_test" () Type: FUNCTION Owner: postgres 785 | -- 786 | 787 | CREATE FUNCTION "raise_test" () RETURNS integer AS ' 788 | DECLARE 789 | 790 | -- Declare an integer variable for testing. 791 | 792 | an_integer INTEGER = 1; 793 | 794 | BEGIN 795 | 796 | -- Raise a debug level message. 797 | 798 | RAISE DEBUG ''The raise_test() function began.''; 799 | 800 | an_integer = an_integer + 1; 801 | 802 | -- Raise a notice stating that the an_integer 803 | -- variable was changed, then raise another notice 804 | -- stating its new value. 805 | 806 | RAISE NOTICE ''Variable an_integer was changed.''; 807 | RAISE NOTICE ''Variable an_integer value is now %.'',an_integer; 808 | 809 | -- Raise an exception. 810 | 811 | RAISE EXCEPTION ''Variable % changed. Aborting transaction.'',an_integer; 812 | 813 | END; 814 | ' LANGUAGE 'plpgsql'; 815 | 816 | -- 817 | -- TOC Entry ID 93 (OID 3628069) 818 | -- 819 | -- Name: "add_shipment" (integer,text) Type: FUNCTION Owner: postgres 820 | -- 821 | 822 | CREATE FUNCTION "add_shipment" (integer,text) RETURNS timestamp with time zone AS ' 823 | DECLARE 824 | customer_id ALIAS FOR $1; 825 | isbn ALIAS FOR $2; 826 | shipment_id INTEGER; 827 | right_now timestamp; 828 | BEGIN 829 | right_now := ''now''; 830 | SELECT INTO shipment_id id FROM shipments ORDER BY id DESC; 831 | shipment_id := shipment_id + 1; 832 | INSERT INTO shipments VALUES ( shipment_id, customer_id, isbn, right_now ); 833 | RETURN right_now; 834 | END; 835 | ' LANGUAGE 'plpgsql'; 836 | 837 | -- 838 | -- TOC Entry ID 102 (OID 3628076) 839 | -- 840 | -- Name: "ship_item" (text,text,text) Type: FUNCTION Owner: postgres 841 | -- 842 | 843 | CREATE FUNCTION "ship_item" (text,text,text) RETURNS integer AS ' 844 | DECLARE 845 | l_name ALIAS FOR $1; 846 | f_name ALIAS FOR $2; 847 | book_isbn ALIAS FOR $3; 848 | book_id INTEGER; 849 | customer_id INTEGER; 850 | 851 | BEGIN 852 | 853 | SELECT INTO customer_id get_customer_id(l_name,f_name); 854 | 855 | IF customer_id = -1 THEN 856 | RETURN -1; 857 | END IF; 858 | 859 | SELECT INTO book_id book_id FROM editions WHERE isbn = book_isbn; 860 | 861 | IF NOT FOUND THEN 862 | RETURN -1; 863 | END IF; 864 | 865 | PERFORM add_shipment(customer_id,book_isbn); 866 | 867 | RETURN 1; 868 | END; 869 | ' LANGUAGE 'plpgsql'; 870 | 871 | -- 872 | -- TOC Entry ID 103 (OID 3628114) 873 | -- 874 | -- Name: "check_book_addition" () Type: FUNCTION Owner: postgres 875 | -- 876 | 877 | CREATE FUNCTION "check_book_addition" () RETURNS opaque AS ' 878 | DECLARE 879 | id_number INTEGER; 880 | book_isbn TEXT; 881 | BEGIN 882 | 883 | SELECT INTO id_number id FROM customers WHERE id = NEW.customer_id; 884 | 885 | IF NOT FOUND THEN 886 | RAISE EXCEPTION ''Invalid customer ID number.''; 887 | END IF; 888 | 889 | SELECT INTO book_isbn isbn FROM editions WHERE isbn = NEW.isbn; 890 | 891 | IF NOT FOUND THEN 892 | RAISE EXCEPTION ''Invalid ISBN.''; 893 | END IF; 894 | 895 | UPDATE stock SET stock = stock -1 WHERE isbn = NEW.isbn; 896 | 897 | RETURN NEW; 898 | END; 899 | ' LANGUAGE 'plpgsql'; 900 | 901 | -- 902 | -- TOC Entry ID 28 (OID 3628246) 903 | -- 904 | -- Name: stock_view Type: VIEW Owner: postgres 905 | -- 906 | 907 | CREATE VIEW "stock_view" as SELECT stock.isbn, stock.retail, stock.stock FROM stock; 908 | 909 | -- 910 | -- TOC Entry ID 30 (OID 3628247) 911 | -- 912 | -- Name: favorite_books Type: TABLE Owner: manager 913 | -- 914 | 915 | CREATE TABLE "favorite_books" ( 916 | "employee_id" integer, 917 | "books" text[] 918 | ); 919 | 920 | -- 921 | -- TOC Entry ID 8 (OID 3628626) 922 | -- 923 | -- Name: shipments_ship_id_seq Type: SEQUENCE Owner: manager 924 | -- 925 | 926 | CREATE SEQUENCE "shipments_ship_id_seq" start 0 increment 1 maxvalue 2147483647 minvalue 0 cache 1 ; 927 | 928 | -- 929 | -- TOC Entry ID 74 (OID 3628648) 930 | -- 931 | -- Name: "check_shipment_addition" () Type: FUNCTION Owner: postgres 932 | -- 933 | 934 | CREATE FUNCTION "check_shipment_addition" () RETURNS opaque AS ' 935 | DECLARE 936 | -- Declare a variable to hold the customer ID. 937 | id_number INTEGER; 938 | 939 | -- Declare a variable to hold the ISBN. 940 | book_isbn TEXT; 941 | BEGIN 942 | 943 | -- If there is an ID number that matches the customer ID in 944 | -- the new table, retrieve it from the customers table. 945 | SELECT INTO id_number id FROM customers WHERE id = NEW.customer_id; 946 | 947 | -- If there was no matching ID number, raise an exception. 948 | IF NOT FOUND THEN 949 | RAISE EXCEPTION ''Invalid customer ID number.''; 950 | END IF; 951 | 952 | -- If there is an ISBN that matches the ISBN specified in the 953 | -- new table, retrieve it from the editions table. 954 | SELECT INTO book_isbn isbn FROM editions WHERE isbn = NEW.isbn; 955 | 956 | -- If there is no matching ISBN, raise an exception. 957 | IF NOT FOUND THEN 958 | RAISE EXCEPTION ''Invalid ISBN.''; 959 | END IF; 960 | 961 | -- If the previous checks succeeded, update the stock amount 962 | -- for INSERT commands. 963 | IF TG_OP = ''INSERT'' THEN 964 | UPDATE stock SET stock = stock -1 WHERE isbn = NEW.isbn; 965 | END IF; 966 | 967 | RETURN NEW; 968 | END; 969 | ' LANGUAGE 'plpgsql'; 970 | 971 | -- 972 | -- TOC Entry ID 31 (OID 3628899) 973 | -- 974 | -- Name: employees Type: TABLE Owner: postgres 975 | -- 976 | 977 | CREATE TABLE "employees" ( 978 | "id" integer NOT NULL, 979 | "last_name" text NOT NULL, 980 | "first_name" text, 981 | CONSTRAINT "employees_id" CHECK ((id > 100)), 982 | Constraint "employees_pkey" Primary Key ("id") 983 | ); 984 | 985 | -- 986 | -- TOC Entry ID 32 (OID 3629174) 987 | -- 988 | -- Name: editions Type: TABLE Owner: manager 989 | -- 990 | 991 | CREATE TABLE "editions" ( 992 | "isbn" text NOT NULL, 993 | "book_id" integer, 994 | "edition" integer, 995 | "publisher_id" integer, 996 | "publication" date, 997 | "type" character(1), 998 | CONSTRAINT "integrity" CHECK (((book_id NOTNULL) AND (edition NOTNULL))), 999 | Constraint "pkey" Primary Key ("isbn") 1000 | ); 1001 | 1002 | -- 1003 | -- TOC Entry ID 10 (OID 3629402) 1004 | -- 1005 | -- Name: author_ids Type: SEQUENCE Owner: manager 1006 | -- 1007 | 1008 | CREATE SEQUENCE "author_ids" start 0 increment 1 maxvalue 2147483647 minvalue 0 cache 1 ; 1009 | 1010 | -- 1011 | -- TOC Entry ID 35 (OID 3629424) 1012 | -- 1013 | -- Name: distinguished_authors Type: TABLE Owner: manager 1014 | -- 1015 | 1016 | CREATE TABLE "distinguished_authors" ( 1017 | "award" text 1018 | ) 1019 | INHERITS ("authors"); 1020 | 1021 | -- 1022 | -- TOC Entry ID 107 (OID 3726476) 1023 | -- 1024 | -- Name: "isbn_to_title" (text) Type: FUNCTION Owner: manager 1025 | -- 1026 | 1027 | CREATE FUNCTION "isbn_to_title" (text) RETURNS text AS 'SELECT title FROM books 1028 | JOIN editions AS e (isbn, id) 1029 | USING (id) 1030 | WHERE isbn = $1' LANGUAGE 'sql'; 1031 | 1032 | -- 1033 | -- TOC Entry ID 36 (OID 3727889) 1034 | -- 1035 | -- Name: favorite_authors Type: TABLE Owner: manager 1036 | -- 1037 | 1038 | CREATE TABLE "favorite_authors" ( 1039 | "employee_id" integer, 1040 | "authors_and_titles" text[] 1041 | ); 1042 | 1043 | -- 1044 | -- TOC Entry ID 99 (OID 3728728) 1045 | -- 1046 | -- Name: "get_customer_name" (integer) Type: FUNCTION Owner: postgres 1047 | -- 1048 | 1049 | CREATE FUNCTION "get_customer_name" (integer) RETURNS text AS ' 1050 | DECLARE 1051 | 1052 | -- Declare aliases for user input. 1053 | customer_id ALIAS FOR $1; 1054 | 1055 | -- Declare variables to hold the customer name. 1056 | customer_fname TEXT; 1057 | customer_lname TEXT; 1058 | 1059 | BEGIN 1060 | 1061 | -- Retrieve the customer first and last name for the customer whose 1062 | -- ID matches the value supplied as a function argument. 1063 | SELECT INTO customer_fname, customer_lname 1064 | first_name, last_name FROM customers 1065 | WHERE id = customer_id; 1066 | 1067 | -- Return the name. 1068 | RETURN customer_fname || '' '' || customer_lname; 1069 | END; 1070 | ' LANGUAGE 'plpgsql'; 1071 | 1072 | -- 1073 | -- TOC Entry ID 100 (OID 3728729) 1074 | -- 1075 | -- Name: "get_customer_id" (text,text) Type: FUNCTION Owner: postgres 1076 | -- 1077 | 1078 | CREATE FUNCTION "get_customer_id" (text,text) RETURNS integer AS ' 1079 | DECLARE 1080 | 1081 | -- Declare aliases for user input. 1082 | l_name ALIAS FOR $1; 1083 | f_name ALIAS FOR $2; 1084 | 1085 | -- Declare a variable to hold the customer ID number. 1086 | customer_id INTEGER; 1087 | 1088 | BEGIN 1089 | 1090 | -- Retrieve the customer ID number of the customer whose first and last 1091 | -- name match the values supplied as function arguments. 1092 | SELECT INTO customer_id id FROM customers 1093 | WHERE last_name = l_name AND first_name = f_name; 1094 | 1095 | -- Return the ID number. 1096 | RETURN customer_id; 1097 | END; 1098 | ' LANGUAGE 'plpgsql'; 1099 | 1100 | -- 1101 | -- TOC Entry ID 101 (OID 3728730) 1102 | -- 1103 | -- Name: "get_author" (text) Type: FUNCTION Owner: postgres 1104 | -- 1105 | 1106 | CREATE FUNCTION "get_author" (text) RETURNS text AS ' 1107 | DECLARE 1108 | 1109 | -- Declare an alias for the function argument, 1110 | -- which should be the first name of an author. 1111 | f_name ALIAS FOR $1; 1112 | 1113 | -- Declare a variable with the same type as 1114 | -- the last_name field of the authors table. 1115 | l_name authors.last_name%TYPE; 1116 | 1117 | BEGIN 1118 | 1119 | -- Retrieve the last name of an author from the 1120 | -- authors table whose first name matches the 1121 | -- argument received by the function, and 1122 | -- insert it into the l_name variable. 1123 | SELECT INTO l_name last_name FROM authors WHERE first_name = f_name; 1124 | 1125 | -- Return the first name and last name, separated 1126 | -- by a space. 1127 | return f_name || '' '' || l_name; 1128 | 1129 | END; 1130 | ' LANGUAGE 'plpgsql'; 1131 | 1132 | -- 1133 | -- TOC Entry ID 97 (OID 3728759) 1134 | -- 1135 | -- Name: "get_author" (integer) Type: FUNCTION Owner: postgres 1136 | -- 1137 | 1138 | CREATE FUNCTION "get_author" (integer) RETURNS text AS ' 1139 | DECLARE 1140 | 1141 | -- Declare an alias for the function argument, 1142 | -- which should be the id of the author. 1143 | author_id ALIAS FOR $1; 1144 | 1145 | -- Declare a variable that uses the structure of 1146 | -- the authors table. 1147 | found_author authors%ROWTYPE; 1148 | 1149 | BEGIN 1150 | 1151 | -- Retrieve a row of author information for 1152 | -- the author whose id number matches 1153 | -- the argument received by the function. 1154 | SELECT INTO found_author * FROM authors WHERE id = author_id; 1155 | 1156 | -- Return the first 1157 | RETURN found_author.first_name || '' '' || found_author.last_name; 1158 | 1159 | END; 1160 | ' LANGUAGE 'plpgsql'; 1161 | 1162 | -- 1163 | -- TOC Entry ID 70 (OID 3743412) 1164 | -- 1165 | -- Name: "html_linebreaks" (text) Type: FUNCTION Owner: postgres 1166 | -- 1167 | 1168 | CREATE FUNCTION "html_linebreaks" (text) RETURNS text AS ' 1169 | DECLARE 1170 | formatted_string text := ''''; 1171 | BEGIN 1172 | FOR i IN 0 .. length($1) LOOP 1173 | IF substr($1, i, 1) = '' 1174 | '' THEN 1175 | formatted_string := formatted_string || ''
''; 1176 | ELSE 1177 | formatted_string := formatted_string || substr($1, i, 1); 1178 | END IF; 1179 | END LOOP; 1180 | RETURN formatted_string; 1181 | END; 1182 | ' LANGUAGE 'plpgsql'; 1183 | 1184 | -- 1185 | -- TOC Entry ID 37 (OID 3751599) 1186 | -- 1187 | -- Name: text_sorting Type: TABLE Owner: postgres 1188 | -- 1189 | 1190 | CREATE TABLE "text_sorting" ( 1191 | "letter" character(1) 1192 | ); 1193 | 1194 | -- 1195 | -- TOC Entry ID 38 (OID 3751882) 1196 | -- 1197 | -- Name: subjects Type: TABLE Owner: postgres 1198 | -- 1199 | 1200 | CREATE TABLE "subjects" ( 1201 | "id" integer NOT NULL, 1202 | "subject" text, 1203 | "location" text, 1204 | Constraint "subjects_pkey" Primary Key ("id") 1205 | ); 1206 | 1207 | -- 1208 | -- TOC Entry ID 108 (OID 3751924) 1209 | -- 1210 | -- Name: sum(text) Type: AGGREGATE Owner: postgres 1211 | -- 1212 | 1213 | CREATE AGGREGATE sum ( BASETYPE = text, SFUNC = textcat, STYPE = text, INITCOND = '' ); 1214 | 1215 | -- 1216 | -- TOC Entry ID 39 (OID 3751975) 1217 | -- 1218 | -- Name: alternate_stock Type: TABLE Owner: postgres 1219 | -- 1220 | 1221 | CREATE TABLE "alternate_stock" ( 1222 | "isbn" text, 1223 | "cost" numeric(5,2), 1224 | "retail" numeric(5,2), 1225 | "stock" integer 1226 | ); 1227 | 1228 | -- 1229 | -- TOC Entry ID 40 (OID 3752020) 1230 | -- 1231 | -- Name: book_backup Type: TABLE Owner: postgres 1232 | -- 1233 | 1234 | CREATE TABLE "book_backup" ( 1235 | "id" integer, 1236 | "title" text, 1237 | "author_id" integer, 1238 | "subject_id" integer 1239 | ); 1240 | 1241 | -- 1242 | -- TOC Entry ID 80 (OID 3752102) 1243 | -- 1244 | -- Name: "sync_authors_and_books" () Type: FUNCTION Owner: postgres 1245 | -- 1246 | 1247 | CREATE FUNCTION "sync_authors_and_books" () RETURNS opaque AS ' 1248 | BEGIN 1249 | IF TG_OP = ''UPDATE'' THEN 1250 | UPDATE books SET author_id = new.id WHERE author_id = old.id; 1251 | END IF; 1252 | RETURN new; 1253 | END; 1254 | ' LANGUAGE 'plpgsql'; 1255 | 1256 | -- 1257 | -- TOC Entry ID 41 (OID 4063343) 1258 | -- 1259 | -- Name: schedules Type: TABLE Owner: postgres 1260 | -- 1261 | 1262 | CREATE TABLE "schedules" ( 1263 | "employee_id" integer NOT NULL, 1264 | "schedule" text, 1265 | Constraint "schedules_pkey" Primary Key ("employee_id") 1266 | ); 1267 | 1268 | -- 1269 | -- TOC Entry ID 42 (OID 4063653) 1270 | -- 1271 | -- Name: recent_shipments Type: VIEW Owner: postgres 1272 | -- 1273 | 1274 | CREATE VIEW "recent_shipments" as SELECT count(*) AS num_shipped, max(shipments.ship_date) AS max, b.title FROM ((shipments JOIN editions USING (isbn)) NATURAL JOIN books b(book_id)) GROUP BY b.title ORDER BY count(*) DESC; 1275 | 1276 | -- 1277 | -- Data for TOC Entry ID 112 (OID 3117548) 1278 | -- 1279 | -- Name: publishers Type: TABLE DATA Owner: postgres 1280 | -- 1281 | 1282 | 1283 | COPY "publishers" FROM stdin; 1284 | 150 Kids Can Press Kids Can Press, 29 Birch Ave. Toronto, ON M4V 1E2 1285 | 91 Henry Holt & Company, Inc. Henry Holt & Company, Inc. 115 West 18th Street New York, NY 10011 1286 | 113 O'Reilly & Associates O'Reilly & Associates, Inc. 101 Morris St, Sebastopol, CA 95472 1287 | 62 Watson-Guptill Publications 1515 Boradway, New York, NY 10036 1288 | 105 Noonday Press Farrar Straus & Giroux Inc, 19 Union Square W, New York, NY 10003 1289 | 99 Ace Books The Berkley Publishing Group, Penguin Putnam Inc, 375 Hudson St, New York, NY 10014 1290 | 101 Roc Penguin Putnam Inc, 375 Hudson St, New York, NY 10014 1291 | 163 Mojo Press Mojo Press, PO Box 1215, Dripping Springs, TX 78720 1292 | 171 Books of Wonder Books of Wonder, 16 W. 18th St. New York, NY, 10011 1293 | 102 Penguin Penguin Putnam Inc, 375 Hudson St, New York, NY 10014 1294 | 75 Doubleday Random House, Inc, 1540 Broadway, New York, NY 10036 1295 | 65 HarperCollins HarperCollins Publishers, 10 E 53rd St, New York, NY 10022 1296 | 59 Random House Random House, Inc, 1540 Broadway, New York, NY 10036 1297 | \. 1298 | -- 1299 | -- Data for TOC Entry ID 113 (OID 3389594) 1300 | -- 1301 | -- Name: authors Type: TABLE DATA Owner: manager 1302 | -- 1303 | 1304 | 1305 | COPY "authors" FROM stdin; 1306 | 1111 Denham Ariel 1307 | 1212 Worsley John 1308 | 15990 Bourgeois Paulette 1309 | 25041 Bianco Margery Williams 1310 | 16 Alcott Louisa May 1311 | 4156 King Stephen 1312 | 1866 Herbert Frank 1313 | 1644 Hogarth Burne 1314 | 2031 Brown Margaret Wise 1315 | 115 Poe Edgar Allen 1316 | 7805 Lutz Mark 1317 | 7806 Christiansen Tom 1318 | 1533 Brautigan Richard 1319 | 1717 Brite Poppy Z. 1320 | 2112 Gorey Edward 1321 | 2001 Clarke Arthur C. 1322 | 1213 Brookins Andrew 1323 | \. 1324 | -- 1325 | -- Data for TOC Entry ID 114 (OID 3389632) 1326 | -- 1327 | -- Name: states Type: TABLE DATA Owner: postgres 1328 | -- 1329 | 1330 | 1331 | COPY "states" FROM stdin; 1332 | 42 Washington WA 1333 | 51 Oregon OR 1334 | \. 1335 | -- 1336 | -- Data for TOC Entry ID 115 (OID 3389702) 1337 | -- 1338 | -- Name: my_list Type: TABLE DATA Owner: postgres 1339 | -- 1340 | 1341 | 1342 | COPY "my_list" FROM stdin; 1343 | Pick up laundry. 1344 | Send out bills. 1345 | Wrap up Grand Unifying Theory for publication. 1346 | \. 1347 | -- 1348 | -- Data for TOC Entry ID 116 (OID 3390348) 1349 | -- 1350 | -- Name: stock Type: TABLE DATA Owner: postgres 1351 | -- 1352 | 1353 | 1354 | COPY "stock" FROM stdin; 1355 | 0385121679 29.00 36.95 65 1356 | 039480001X 30.00 32.95 31 1357 | 0394900014 23.00 23.95 0 1358 | 044100590X 36.00 45.95 89 1359 | 0441172717 17.00 21.95 77 1360 | 0451160916 24.00 28.95 22 1361 | 0451198492 36.00 46.95 0 1362 | 0451457994 17.00 22.95 0 1363 | 0590445065 23.00 23.95 10 1364 | 0679803335 20.00 24.95 18 1365 | 0694003611 25.00 28.95 50 1366 | 0760720002 18.00 23.95 28 1367 | 0823015505 26.00 28.95 16 1368 | 0929605942 19.00 21.95 25 1369 | 1885418035 23.00 24.95 77 1370 | 0394800753 16.00 16.95 4 1371 | \. 1372 | -- 1373 | -- Data for TOC Entry ID 117 (OID 3390653) 1374 | -- 1375 | -- Name: numeric_values Type: TABLE DATA Owner: postgres 1376 | -- 1377 | 1378 | 1379 | COPY "numeric_values" FROM stdin; 1380 | 68719476736.000000 1381 | 68719476737.000000 1382 | 6871947673778.000000 1383 | 999999999999999999999999.999900 1384 | 999999999999999999999999.999999 1385 | -999999999999999999999999.999999 1386 | -100000000000000000000000.999999 1387 | 1.999999 1388 | 2.000000 1389 | 2.000000 1390 | 999999999999999999999999.999999 1391 | 999999999999999999999999.000000 1392 | \. 1393 | -- 1394 | -- Data for TOC Entry ID 118 (OID 3390866) 1395 | -- 1396 | -- Name: daily_inventory Type: TABLE DATA Owner: postgres 1397 | -- 1398 | 1399 | 1400 | COPY "daily_inventory" FROM stdin; 1401 | 039480001X t 1402 | 044100590X t 1403 | 0451198492 f 1404 | 0394900014 f 1405 | 0441172717 t 1406 | 0451160916 f 1407 | 0385121679 \N 1408 | \. 1409 | -- 1410 | -- Data for TOC Entry ID 119 (OID 3391084) 1411 | -- 1412 | -- Name: money_example Type: TABLE DATA Owner: postgres 1413 | -- 1414 | 1415 | 1416 | COPY "money_example" FROM stdin; 1417 | $12.24 12.24 1418 | \. 1419 | -- 1420 | -- Data for TOC Entry ID 120 (OID 3391184) 1421 | -- 1422 | -- Name: shipments Type: TABLE DATA Owner: postgres 1423 | -- 1424 | 1425 | 1426 | COPY "shipments" FROM stdin; 1427 | 375 142 039480001X 2001-08-06 09:29:21-07 1428 | 323 671 0451160916 2001-08-14 10:36:41-07 1429 | 998 1045 0590445065 2001-08-12 12:09:47-07 1430 | 749 172 0694003611 2001-08-11 10:52:34-07 1431 | 662 655 0679803335 2001-08-09 07:30:07-07 1432 | 806 1125 0760720002 2001-08-05 09:34:04-07 1433 | 102 146 0394900014 2001-08-11 13:34:08-07 1434 | 813 112 0385121679 2001-08-08 09:53:46-07 1435 | 652 724 1885418035 2001-08-14 13:41:39-07 1436 | 599 430 0929605942 2001-08-10 08:29:42-07 1437 | 969 488 0441172717 2001-08-14 08:42:58-07 1438 | 433 898 044100590X 2001-08-12 08:46:35-07 1439 | 660 409 0451457994 2001-08-07 11:56:42-07 1440 | 310 738 0451198492 2001-08-15 14:02:01-07 1441 | 510 860 0823015505 2001-08-14 07:33:47-07 1442 | 997 185 039480001X 2001-08-10 13:47:52-07 1443 | 999 221 0451160916 2001-08-14 13:45:51-07 1444 | 56 880 0590445065 2001-08-14 13:49:00-07 1445 | 72 574 0694003611 2001-08-06 07:49:44-07 1446 | 146 270 039480001X 2001-08-13 09:42:10-07 1447 | 981 652 0451160916 2001-08-08 08:36:44-07 1448 | 95 480 0590445065 2001-08-10 07:29:52-07 1449 | 593 476 0694003611 2001-08-15 11:57:40-07 1450 | 977 853 0679803335 2001-08-09 09:30:46-07 1451 | 117 185 0760720002 2001-08-07 13:00:48-07 1452 | 406 1123 0394900014 2001-08-13 09:47:04-07 1453 | 340 1149 0385121679 2001-08-12 13:39:22-07 1454 | 871 388 1885418035 2001-08-07 11:31:57-07 1455 | 1000 221 039480001X 2001-09-14 16:46:32-07 1456 | 1001 107 039480001X 2001-09-14 17:42:22-07 1457 | 754 107 0394800753 2001-08-11 09:55:05-07 1458 | 458 107 0394800753 2001-08-07 10:58:36-07 1459 | 189 107 0394800753 2001-08-06 11:46:36-07 1460 | 720 107 0394800753 2001-08-08 10:46:13-07 1461 | 1002 107 0394800753 2001-09-22 11:23:28-07 1462 | 2 107 0394800753 2001-09-22 20:58:56-07 1463 | \. 1464 | -- 1465 | -- Data for TOC Entry ID 121 (OID 3391454) 1466 | -- 1467 | -- Name: customers Type: TABLE DATA Owner: manager 1468 | -- 1469 | 1470 | 1471 | COPY "customers" FROM stdin; 1472 | 107 Jackson Annie 1473 | 112 Gould Ed 1474 | 142 Allen Chad 1475 | 146 Williams James 1476 | 172 Brown Richard 1477 | 185 Morrill Eric 1478 | 221 King Jenny 1479 | 270 Bollman Julie 1480 | 388 Morrill Royce 1481 | 409 Holloway Christine 1482 | 430 Black Jean 1483 | 476 Clark James 1484 | 480 Thomas Rich 1485 | 488 Young Trevor 1486 | 574 Bennett Laura 1487 | 652 Anderson Jonathan 1488 | 655 Olson Dave 1489 | 671 Brown Chuck 1490 | 723 Eisele Don 1491 | 724 Holloway Adam 1492 | 738 Gould Shirley 1493 | 830 Robertson Royce 1494 | 853 Black Wendy 1495 | 860 Owens Tim 1496 | 880 Robinson Tammy 1497 | 898 Gerdes Kate 1498 | 964 Gould Ramon 1499 | 1045 Owens Jean 1500 | 1125 Bollman Owen 1501 | 1149 Becker Owen 1502 | 1123 Corner Kathy 1503 | \. 1504 | -- 1505 | -- Data for TOC Entry ID 122 (OID 3574043) 1506 | -- 1507 | -- Name: book_queue Type: TABLE DATA Owner: postgres 1508 | -- 1509 | 1510 | 1511 | COPY "book_queue" FROM stdin; 1512 | Learning Python 7805 4 t 1513 | Perl Cookbook 7806 4 t 1514 | \. 1515 | -- 1516 | -- Data for TOC Entry ID 123 (OID 3574983) 1517 | -- 1518 | -- Name: stock_backup Type: TABLE DATA Owner: postgres 1519 | -- 1520 | 1521 | 1522 | COPY "stock_backup" FROM stdin; 1523 | 0385121679 29.00 36.95 65 1524 | 039480001X 30.00 32.95 31 1525 | 0394800753 16.00 16.95 0 1526 | 0394900014 23.00 23.95 0 1527 | 044100590X 36.00 45.95 89 1528 | 0441172717 17.00 21.95 77 1529 | 0451160916 24.00 28.95 22 1530 | 0451198492 36.00 46.95 0 1531 | 0451457994 17.00 22.95 0 1532 | 0590445065 23.00 23.95 10 1533 | 0679803335 20.00 24.95 18 1534 | 0694003611 25.00 28.95 50 1535 | 0760720002 18.00 23.95 28 1536 | 0823015505 26.00 28.95 16 1537 | 0929605942 19.00 21.95 25 1538 | 1885418035 23.00 24.95 77 1539 | \. 1540 | -- 1541 | -- Data for TOC Entry ID 124 (OID 3628247) 1542 | -- 1543 | -- Name: favorite_books Type: TABLE DATA Owner: manager 1544 | -- 1545 | 1546 | 1547 | COPY "favorite_books" FROM stdin; 1548 | 102 {"The Hitchhiker's Guide to the Galaxy","The Restauraunt at the End of the Universe"} 1549 | 103 {"There and Back Again: A Hobbit's Holiday","Kittens Squared"} 1550 | \. 1551 | -- 1552 | -- Data for TOC Entry ID 125 (OID 3628899) 1553 | -- 1554 | -- Name: employees Type: TABLE DATA Owner: postgres 1555 | -- 1556 | 1557 | 1558 | COPY "employees" FROM stdin; 1559 | 101 Appel Vincent 1560 | 102 Holloway Michael 1561 | 105 Connoly Sarah 1562 | 104 Noble Ben 1563 | 103 Joble David 1564 | 106 Hall Timothy 1565 | 1008 Williams \N 1566 | \. 1567 | -- 1568 | -- Data for TOC Entry ID 126 (OID 3629174) 1569 | -- 1570 | -- Name: editions Type: TABLE DATA Owner: manager 1571 | -- 1572 | 1573 | 1574 | COPY "editions" FROM stdin; 1575 | 039480001X 1608 1 59 1957-03-01 h 1576 | 0451160916 7808 1 75 1981-08-01 p 1577 | 0394800753 1590 1 59 1949-03-01 p 1578 | 0590445065 25908 1 150 1987-03-01 p 1579 | 0694003611 1501 1 65 1947-03-04 p 1580 | 0679803335 1234 1 102 1922-01-01 p 1581 | 0760720002 190 1 91 1868-01-01 p 1582 | 0394900014 1608 1 59 1957-01-01 p 1583 | 0385121679 7808 2 75 1993-10-01 h 1584 | 1885418035 156 1 163 1995-03-28 p 1585 | 0929605942 156 2 171 1998-12-01 p 1586 | 0441172717 4513 2 99 1998-09-01 p 1587 | 044100590X 4513 3 99 1999-10-01 h 1588 | 0451457994 4267 3 101 2000-09-12 p 1589 | 0451198492 4267 3 101 1999-10-01 h 1590 | 0823015505 2038 1 62 1958-01-01 p 1591 | 0596000855 41473 2 113 2001-03-01 p 1592 | \. 1593 | -- 1594 | -- Data for TOC Entry ID 127 (OID 3629264) 1595 | -- 1596 | -- Name: books Type: TABLE DATA Owner: manager 1597 | -- 1598 | 1599 | 1600 | COPY "books" FROM stdin; 1601 | 7808 The Shining 4156 9 1602 | 4513 Dune 1866 15 1603 | 4267 2001: A Space Odyssey 2001 15 1604 | 1608 The Cat in the Hat 1809 2 1605 | 1590 Bartholomew and the Oobleck 1809 2 1606 | 25908 Franklin in the Dark 15990 2 1607 | 1501 Goodnight Moon 2031 2 1608 | 190 Little Women 16 6 1609 | 1234 The Velveteen Rabbit 25041 3 1610 | 2038 Dynamic Anatomy 1644 0 1611 | 156 The Tell-Tale Heart 115 9 1612 | 41473 Programming Python 7805 4 1613 | 41477 Learning Python 7805 4 1614 | 41478 Perl Cookbook 7806 4 1615 | 41472 Practical PostgreSQL 1212 4 1616 | \. 1617 | -- 1618 | -- Data for TOC Entry ID 128 (OID 3629424) 1619 | -- 1620 | -- Name: distinguished_authors Type: TABLE DATA Owner: manager 1621 | -- 1622 | 1623 | 1624 | COPY "distinguished_authors" FROM stdin; 1625 | 25043 Simon Neil Pulitzer Prize 1626 | 1809 Geisel Theodor Seuss Pulitzer Prize 1627 | \. 1628 | -- 1629 | -- Data for TOC Entry ID 129 (OID 3727889) 1630 | -- 1631 | -- Name: favorite_authors Type: TABLE DATA Owner: manager 1632 | -- 1633 | 1634 | 1635 | COPY "favorite_authors" FROM stdin; 1636 | 102 {{"J.R.R. Tolkien","The Silmarillion"},{"Charles Dickens","Great Expectations"},{"Ariel Denham","Attic Lives"}} 1637 | \. 1638 | -- 1639 | -- Data for TOC Entry ID 130 (OID 3751599) 1640 | -- 1641 | -- Name: text_sorting Type: TABLE DATA Owner: postgres 1642 | -- 1643 | 1644 | 1645 | COPY "text_sorting" FROM stdin; 1646 | 0 1647 | 1 1648 | 2 1649 | 3 1650 | A 1651 | B 1652 | C 1653 | D 1654 | a 1655 | b 1656 | c 1657 | d 1658 | \. 1659 | -- 1660 | -- Data for TOC Entry ID 131 (OID 3751882) 1661 | -- 1662 | -- Name: subjects Type: TABLE DATA Owner: postgres 1663 | -- 1664 | 1665 | 1666 | COPY "subjects" FROM stdin; 1667 | 0 Arts Creativity St 1668 | 1 Business Productivity Ave 1669 | 2 Children's Books Kids Ct 1670 | 3 Classics Academic Rd 1671 | 4 Computers Productivity Ave 1672 | 5 Cooking Creativity St 1673 | 6 Drama Main St 1674 | 7 Entertainment Main St 1675 | 8 History Academic Rd 1676 | 9 Horror Black Raven Dr 1677 | 10 Mystery Black Raven Dr 1678 | 11 Poetry Sunset Dr 1679 | 12 Religion \N 1680 | 13 Romance Main St 1681 | 14 Science Productivity Ave 1682 | 15 Science Fiction Main St 1683 | \. 1684 | -- 1685 | -- Data for TOC Entry ID 132 (OID 3751975) 1686 | -- 1687 | -- Name: alternate_stock Type: TABLE DATA Owner: postgres 1688 | -- 1689 | 1690 | 1691 | COPY "alternate_stock" FROM stdin; 1692 | 0385121679 29.00 36.95 65 1693 | 039480001X 30.00 32.95 31 1694 | 0394900014 23.00 23.95 0 1695 | 044100590X 36.00 45.95 89 1696 | 0441172717 17.00 21.95 77 1697 | 0451160916 24.00 28.95 22 1698 | 0451198492 36.00 46.95 0 1699 | 0451457994 17.00 22.95 0 1700 | 0590445065 23.00 23.95 10 1701 | 0679803335 20.00 24.95 18 1702 | 0694003611 25.00 28.95 50 1703 | 0760720002 18.00 23.95 28 1704 | 0823015505 26.00 28.95 16 1705 | 0929605942 19.00 21.95 25 1706 | 1885418035 23.00 24.95 77 1707 | 0394800753 16.00 16.95 4 1708 | \. 1709 | -- 1710 | -- Data for TOC Entry ID 133 (OID 3752020) 1711 | -- 1712 | -- Name: book_backup Type: TABLE DATA Owner: postgres 1713 | -- 1714 | 1715 | 1716 | COPY "book_backup" FROM stdin; 1717 | 7808 The Shining 4156 9 1718 | 4513 Dune 1866 15 1719 | 4267 2001: A Space Odyssey 2001 15 1720 | 1608 The Cat in the Hat 1809 2 1721 | 1590 Bartholomew and the Oobleck 1809 2 1722 | 25908 Franklin in the Dark 15990 2 1723 | 1501 Goodnight Moon 2031 2 1724 | 190 Little Women 16 6 1725 | 1234 The Velveteen Rabbit 25041 3 1726 | 2038 Dynamic Anatomy 1644 0 1727 | 156 The Tell-Tale Heart 115 9 1728 | 41472 Practical PostgreSQL 1212 4 1729 | 41473 Programming Python 7805 4 1730 | 41477 Learning Python 7805 4 1731 | 41478 Perl Cookbook 7806 4 1732 | 7808 The Shining 4156 9 1733 | 4513 Dune 1866 15 1734 | 4267 2001: A Space Odyssey 2001 15 1735 | 1608 The Cat in the Hat 1809 2 1736 | 1590 Bartholomew and the Oobleck 1809 2 1737 | 25908 Franklin in the Dark 15990 2 1738 | 1501 Goodnight Moon 2031 2 1739 | 190 Little Women 16 6 1740 | 1234 The Velveteen Rabbit 25041 3 1741 | 2038 Dynamic Anatomy 1644 0 1742 | 156 The Tell-Tale Heart 115 9 1743 | 41473 Programming Python 7805 4 1744 | 41477 Learning Python 7805 4 1745 | 41478 Perl Cookbook 7806 4 1746 | 41472 Practical PostgreSQL 1212 4 1747 | \. 1748 | -- 1749 | -- Data for TOC Entry ID 134 (OID 4063343) 1750 | -- 1751 | -- Name: schedules Type: TABLE DATA Owner: postgres 1752 | -- 1753 | 1754 | 1755 | COPY "schedules" FROM stdin; 1756 | 102 Mon - Fri, 9am - 5pm 1757 | \. 1758 | -- 1759 | -- TOC Entry ID 45 (OID 3117548) 1760 | -- 1761 | -- Name: "unique_publisher_idx" Type: INDEX Owner: postgres 1762 | -- 1763 | 1764 | CREATE UNIQUE INDEX "unique_publisher_idx" on "publishers" using btree ( "name" "text_ops" ); 1765 | 1766 | -- 1767 | -- TOC Entry ID 43 (OID 3391184) 1768 | -- 1769 | -- Name: "shipments_ship_id_key" Type: INDEX Owner: postgres 1770 | -- 1771 | 1772 | CREATE UNIQUE INDEX "shipments_ship_id_key" on "shipments" using btree ( "id" "int4_ops" ); 1773 | 1774 | -- 1775 | -- TOC Entry ID 44 (OID 3629264) 1776 | -- 1777 | -- Name: "books_title_idx" Type: INDEX Owner: manager 1778 | -- 1779 | 1780 | CREATE INDEX "books_title_idx" on "books" using btree ( "title" "text_ops" ); 1781 | 1782 | -- 1783 | -- TOC Entry ID 46 (OID 3751599) 1784 | -- 1785 | -- Name: "text_idx" Type: INDEX Owner: postgres 1786 | -- 1787 | 1788 | CREATE INDEX "text_idx" on "text_sorting" using btree ( "letter" "bpchar_ops" ); 1789 | 1790 | -- 1791 | -- TOC Entry ID 136 (OID 3628649) 1792 | -- 1793 | -- Name: check_shipment Type: TRIGGER Owner: postgres 1794 | -- 1795 | 1796 | CREATE TRIGGER "check_shipment" BEFORE INSERT OR UPDATE ON "shipments" FOR EACH ROW EXECUTE PROCEDURE "check_shipment_addition" (); 1797 | 1798 | -- 1799 | -- TOC Entry ID 135 (OID 3752103) 1800 | -- 1801 | -- Name: sync_authors_books Type: TRIGGER Owner: manager 1802 | -- 1803 | 1804 | CREATE TRIGGER "sync_authors_books" BEFORE UPDATE ON "authors" FOR EACH ROW EXECUTE PROCEDURE "sync_authors_and_books" (); 1805 | 1806 | -- 1807 | -- TOC Entry ID 139 (OID 4063374) 1808 | -- 1809 | -- Name: "RI_ConstraintTrigger_4063373" Type: TRIGGER Owner: postgres 1810 | -- 1811 | 1812 | CREATE CONSTRAINT TRIGGER "valid_employee" AFTER INSERT OR UPDATE ON "schedules" FROM "employees" NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE "RI_FKey_check_ins" ('valid_employee', 'schedules', 'employees', 'FULL', 'employee_id', 'id'); 1813 | 1814 | -- 1815 | -- TOC Entry ID 137 (OID 4063376) 1816 | -- 1817 | -- Name: "RI_ConstraintTrigger_4063375" Type: TRIGGER Owner: postgres 1818 | -- 1819 | 1820 | CREATE CONSTRAINT TRIGGER "valid_employee" AFTER DELETE ON "employees" FROM "schedules" NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE "RI_FKey_noaction_del" ('valid_employee', 'schedules', 'employees', 'FULL', 'employee_id', 'id'); 1821 | 1822 | -- 1823 | -- TOC Entry ID 138 (OID 4063378) 1824 | -- 1825 | -- Name: "RI_ConstraintTrigger_4063377" Type: TRIGGER Owner: postgres 1826 | -- 1827 | 1828 | CREATE CONSTRAINT TRIGGER "valid_employee" AFTER UPDATE ON "employees" FROM "schedules" NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE "RI_FKey_noaction_upd" ('valid_employee', 'schedules', 'employees', 'FULL', 'employee_id', 'id'); 1829 | 1830 | -- 1831 | -- TOC Entry ID 140 (OID 3752079) 1832 | -- 1833 | -- Name: sync_stock_with_editions Type: RULE Owner: manager 1834 | -- 1835 | 1836 | CREATE RULE sync_stock_with_editions AS ON UPDATE TO editions DO UPDATE stock SET isbn = new.isbn WHERE (stock.isbn = old.isbn); 1837 | -- 1838 | -- TOC Entry ID 5 (OID 3390416) 1839 | -- 1840 | -- Name: subject_ids Type: SEQUENCE SET Owner: 1841 | -- 1842 | 1843 | SELECT setval ('"subject_ids"', 15, 't'); 1844 | 1845 | -- 1846 | -- TOC Entry ID 7 (OID 3574018) 1847 | -- 1848 | -- Name: book_ids Type: SEQUENCE SET Owner: 1849 | -- 1850 | 1851 | SELECT setval ('"book_ids"', 41478, 't'); 1852 | 1853 | -- 1854 | -- TOC Entry ID 9 (OID 3628626) 1855 | -- 1856 | -- Name: shipments_ship_id_seq Type: SEQUENCE SET Owner: 1857 | -- 1858 | 1859 | SELECT setval ('"shipments_ship_id_seq"', 1011, 't'); 1860 | 1861 | -- 1862 | -- TOC Entry ID 11 (OID 3629402) 1863 | -- 1864 | -- Name: author_ids Type: SEQUENCE SET Owner: 1865 | -- 1866 | 1867 | SELECT setval ('"author_ids"', 25044, 't'); 1868 | --------------------------------------------------------------------------------