Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
108 views6 pages

Output Lab1 01

The document shows the user connecting to different databases and schemas, exploring the tables and relations, and running queries. Key details include: - The user connects to the "training1" and "training2" databases and explores the schemas and tables - In "training1", the user views dimension tables in the "ddemo" schema and runs aggregate queries on these tables - In "training2", the user analyzes a "housing" table for duplicate records, removes duplicates, and runs correlation and regression analyses on fields in the de-duplicated table for a specific state

Uploaded by

benben08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
108 views6 pages

Output Lab1 01

The document shows the user connecting to different databases and schemas, exploring the tables and relations, and running queries. Key details include: - The user connects to the "training1" and "training2" databases and explores the schemas and tables - In "training1", the user views dimension tables in the "ddemo" schema and runs aggregate queries on these tables - In "training2", the user analyzes a "housing" table for duplicate records, removes duplicates, and runs correlation and regression analyses on fields in the de-duplicated table for a specific state

Uploaded by

benben08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

[gpadmin@pod4-be ~]$ -bash: ddemo: command not found

-bash: -bash:: command not found


[gpadmin@pod4-be ~]$ \c training1
-bash: c: command not found
[gpadmin@pod4-be ~]$ psql training1
psql (8.2.15)
Type "help" for help.
training1=# psql
training1-# \c training1
You are now connected to database "training1" as user "gpadmin".
training1-# SET search_path TO ddemo, public;
ERROR: syntax error at or near "psql"
LINE 1: psql
^
training1=# \dt
List of relations
Schema |
Name
| Type | Owner | Storage
--------+--------------+-------+---------+--------public | weekly_sales | table | gpadmin | heap
(1 row)
training1=# \dn
List of schemas
Name
| Owner
--------------------+--------ddemo
| gpadmin
gp_toolkit
| gpadmin
information_schema | gpadmin
madlib
| gpadmin
myschema
| gpadmin
pg_aoseg
| gpadmin
pg_bitmapindex
| gpadmin
pg_catalog
| gpadmin
pg_toast
| gpadmin
public
| gpadmin
(10 rows)
training1=# SET search_path TO ddemo, public;
SET
training1=#
training1=# \dt
List of relations
Schema |
Name
| Type | Owner | Storage
--------+---------------------------+-------+---------+------------ddemo | campaign_dim
| table | gpadmin | heap
ddemo | campaign_dim_stage
| table | gpadmin | heap
ddemo | categories_dim
| table | gpadmin | append only
ddemo | city_state_zip
| table | gpadmin | append only
ddemo | customer_addresses_dim
| table | gpadmin | append only
ddemo | customer_demographics
| table | gpadmin | heap
ddemo | customers_dim
| table | gpadmin | append only
ddemo | date_dim
| table | gpadmin | heap
ddemo | day_weights
| table | gpadmin | heap
ddemo | distribution
| table | gpadmin | heap
ddemo | email_addresses_dim
| table | gpadmin | append only
ddemo | female_first_names_xt_err | table | gpadmin | heap
ddemo | kid_friendly_dvds
| table | gpadmin | append only

ddemo |
ddemo |
ddemo |
ddemo |
ddemo |
ddemo |
ddemo |
ddemo |
ddemo |
ddemo |
ddemo |
ddemo |
ddemo |
ddemo |
ddemo |
ddemo |
(29 rows)

kid_friendly_dvds_xt_err
list_c
male_first_names_xt_err
order_lineitems
order_lineitems_stage
orders
payment_methods
products_dim
products_xt_err
raw_zip_city_state_xt_err
state_sales_taxes_xt_err
streets
streets_xt_err
surnames_xt_err
websites_xt_err
weekly_sales

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

table
table
table
table
table
table
table
table
table
table
table
table
table
table
table
table

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

gpadmin
gpadmin
gpadmin
gpadmin
gpadmin
gpadmin
gpadmin
gpadmin
gpadmin
gpadmin
gpadmin
gpadmin
gpadmin
gpadmin
gpadmin
gpadmin

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

heap
heap
heap
append
heap
append
append
append
heap
heap
heap
append
heap
heap
heap
heap

only
only
only
only

only

training1=# \d+ customers_dim


Append-Only Table "ddemo.customer
s_dim"
Column

Type

|
Modifiers
| Storage | Description
-------------+------------------------+--------------------------------------------------------------------+----------+------------customer_id | integer
| not null default nextval('customers_dim_
customer_id_seq'::regclass) | plain
|
first_name | character varying(100) | not null
| extended |
last_name | character varying(200) | not null
| extended |
gender
| character(1)
|
| extended |
Compression Type: quicklz
Compression Level: 1
Block Size: 32768
Checksum: f
Has OIDs: no
Options: appendonly=true, compresstype=quicklz
Distributed by: (customer_id)
training1=# SELECT gender,count(*) FROM customers_dim GROUP BY gender;
gender | count
--------+-------M
| 500959
F
| 499041
(2 rows)
training1=#
training1=#
training1-#
training1-#
training1-#
training1-#
training1-#
training1-#
training1-#

SELECT
c.gender
, AVG(o.item_price) AS avg_price
FROM
ddemo.order_lineitems AS o
JOIN
ddemo.customers_dim AS c
ON o.customer_id = c.customer_id

training1-# GROUP BY c.gender


training1-# ;
gender |
avg_price
--------+--------------------M
| 33.8456101189216746
F
| 33.7982853835904994
(2 rows)
training1-# \q
[gpadmin@pod4-be ~]$
[gpadmin@pod4-be ~]$ cd LAB01
[gpadmin@pod4-be LAB01]$

[gpadmin@pod4-be LAB01]$ psql -d training1 -f lab1p1step6.sql


gender |
avg_price
--------+--------------------M
| 33.8456101189216746
F
| 33.7982853835904994
(2 rows)
[gpadmin@pod4-be LAB01]$ psql -d training1 -f lab1p1step7.sql
sum
|
product_category_name
-------------+---------------------------------27638821.85 | Kitchen
27027249.97 | Home Improvement
17284431.77 | DVD
13628527.17 | Sports
10841356.88 | Automotive Parts and Accessories
9974722.57 | Toy
(6 rows)
[gpadmin@pod4-be LAB01]$

[gpadmin@pod4-be LAB01]$
[gpadmin@pod4-be LAB01]$ psql
psql (8.2.15)
Type "help" for help.
template1=# \c training2
You are now connected to database "training2" as user "gpadmin".
training2=# \dt
List of relations
Schema | Name | Type | Owner | Storage
--------+---------+-------+---------+--------public | fips
| table | gpadmin | heap
public | housing | table | gpadmin | heap
public | persons | table | gpadmin | heap
public | zeta
| table | gpadmin | heap
(4 rows)
training2=#
training2=# \dn

List of schemas
Name
| Owner
--------------------+--------gp_toolkit
| gpadmin
information_schema | gpadmin
madlib
| gpadmin
myschema
| gpadmin
pg_aoseg
| gpadmin
pg_bitmapindex
| gpadmin
pg_catalog
| gpadmin
pg_toast
| gpadmin
public
| gpadmin
(9 rows)
training2=#
training2=# SELECT
training2-# SUM(c) AS total_records
training2-# , SUM(CASE WHEN c>1 THEN c-1 ELSE 0 END) AS total_dupes
training2-# , COUNT(*) AS total_uniques
training2-# FROM (
training2(# SELECT
training2(# COUNT(*) AS c
training2(# FROM
training2(# housing
training2(# GROUP BY
training2(# serialno
training2(# , state
training2(# ) AS dupes
training2-# ;
total_records | total_dupes | total_uniques
---------------+-------------+--------------12515394 |
6257697 |
6257697
(1 row)

training2=# \dt
List of relations
Schema | Name | Type | Owner | Storage
--------+---------+-------+---------+--------public | fips
| table | gpadmin | heap
public | housing | table | gpadmin | heap
public | persons | table | gpadmin | heap
public | zeta
| table | gpadmin | heap
(4 rows)
training2=# DROP TABLE IF EXISTS housing_nodupes;
NOTICE: table "housing_nodupes" does not exist, skipping
DROP TABLE
training2=#
training2-#
training2-#
training2-#
training2-#
training2-#
training2-#

CREATE TABLE housing_nodupes AS


SELECT DISTINCT ON
(serialno, state) *
FROM
housing
DISTRIBUTED BY (serialno, state)
;

SELECT 6257697
training2=#

training2=#
training2=# SELECT
training2-# SUM(c) AS total_records
training2-# , SUM(CASE WHEN c>1 THEN c-1 ELSE 0 END) AS total_dupes
training2-# , COUNT(*) AS total_uniques
training2-# FROM (
training2(# SELECT
training2(# COUNT(*) AS c
training2(# FROM
training2(# housing_nodupes
training2(# GROUP BY
training2(# serialno
training2(# , state
training2(# ) AS dupes
training2-# ;
total_records | total_dupes | total_uniques
---------------+-------------+--------------6257697 |
0 |
6257697
(1 row)
training2=# SELECT
training2-# corr(hinc, rooms)
training2-# FROM
training2-# housing_nodupes
training2-# WHERE
training2-# state = 25
training2-# ;
corr
------------------0.374485423827578
(1 row)

training2=#
training2=# SELECT * FROM fips WHERE code = 25;
code | name
------+-----25 | MA
(1 row)
training2=#
training2=#
training2=# SELECT
training2-# regr_r2(hinc, rooms)
training2-# FROM
training2-# housing_nodupes
training2-# WHERE
training2-# state = 25
training2-# ;
regr_r2

------------------0.140239332659321
(1 row)
training2=#
training2-#
training2-#
training2-#
training2-#
training2-#
training2-#
training2-#
training2-#
training2-#
training2=#

SELECT
serialno
, hinc
, rooms
FROM
housing_nodupes
WHERE
hinc > 0
AND state = 25
;

\a
\o lab1_01.txt
SELECT
serialno
, hinc
, rooms
FROM
housing_nodupes
WHERE
hinc > 0
AND state = 25
;

the output is file lab_01.txt

serialno | hinc | rooms


----------+---------+------45 | 68100 |
2
103 | 359000 |
5
159 | 14700 |
4
697 | 101500 |
9
749 | 38600 |
3
962 | 86480 |
8
1051 | 81300 |
6
1514 | 90000 |
3
1537 | 28000 |
8
1791 | 271800 |
8
1942 | 18200 |
9
2028 | 122300 |
7
2197 | 42400 |
5
2293 | 90000 |
5
2295 | 29000 |
5
2402 |
5300 |
3
2583 | 31000 |
6
2697 | 322000 |
9

You might also like