-
Notifications
You must be signed in to change notification settings - Fork 0
/
terminal-record.txt
232 lines (182 loc) · 8.73 KB
/
terminal-record.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
Aryanti Dwiastuti, [14.02.20 12:02]
Microsoft Windows [Version 10.0.17134.1246]
(c) 2018 Microsoft Corporation. All rights reserved.
C:\Users\asus>psql
'psql' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\asus>postgres --version
'postgres' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\asus>cd..
C:\Users>cd..
C:\>cd xampp
C:\xampp>cd pgsql
C:\xampp\pgsql>cd bin
C:\xampp\pgsql\bin>psql -U postgres
Password for user postgres:
psql (11.4)
Type "help" for help.
postgres=# CREATE DATABASE myshop;
CREATE DATABASE
postgres=# \c myshop
You are now connected to database "myshop" as user "postgres".
myshop=# CREATE TABLE users(id SERIAL NOT NULL PRIMARY KEY, name varchar(255), email varchar(255), password varchar(255));
CREATE TABLE
myshop=# CREATE TABLE items (id SERIAL PRIMARY KEY, name varchar(255), description varchar(255), price int, stock int, category_id int);
CREATE TABLE
myshop=# CREATE TABLE items (id SERIAL PRIMARY KEY, name varchar(255));
ERROR: relation "items" already exists
myshop=# CREATE TABLE category (id SERIAL PRIMARY KEY, name varchar(255));
CREATE TABLE
myshop=# \dt
List of relations
Schema | Name | Type | Owner
--------+----------+-------+----------
public | category | table | postgres
public | items | table | postgres
public | users | table | postgres
(3 rows)
myshop=# \dT
List of data types
Schema | Name | Description
--------+------+-------------
(0 rows)
myshop=# \d category
Table "public.category"
Column | Type | Collation | Nullable | Default
--------+------------------------+-----------+----------+--------------------------------------
id | integer | | not null | nextval('category_id_seq'::regclass)
name | character varying(255) | | |
Indexes:
"category_pkey" PRIMARY KEY, btree (id)
myshop=# \d items
Table "public.items"
Column
Aryanti Dwiastuti, [14.02.20 12:02]
| Type | Collation | Nullable | Default
-------------+------------------------+-----------+----------+-----------------------------------
id | integer | | not null | nextval('items_id_seq'::regclass)
name | character varying(255) | | |
description | character varying(255) | | |
price | integer | | |
stock | integer | | |
category_id | integer | | |
Indexes:
"items_pkey" PRIMARY KEY, btree (id)
myshop=# \d users
Table "public.users"
Column | Type | Collation | Nullable | Default
----------+------------------------+-----------+----------+-----------------------------------
id | integer | | not null | nextval('users_id_seq'::regclass)
name | character varying(255) | | |
email | character varying(255) | | |
password | character varying(255) | | |
Indexes:
"users_pkey" PRIMARY KEY, btree (id)
myshop=# INSERT INTO users VALUES ("John Doe", "[email protected]", "john123");
ERROR: column "John Doe" does not exist
LINE 1: INSERT INTO users VALUES ("John Doe", "[email protected]", "john1...
^
myshop=# INSERT INTO users VALUES ('John Doe', '[email protected]', 'john123');
ERROR: invalid input syntax for integer: "John Doe"
LINE 1: INSERT INTO users VALUES ('John Doe', '[email protected]', 'john1...
^
myshop=# INSERT INTO users (name, email, password) VALUES ('John Doe', '[email protected]', 'john123'), ('Jane Doe', '[email protected]', 'jenita123');
INSERT 0 2
myshop=# select * from users
myshop-# ;
id | name | email | password
----+----------+--------------+-----------
1 | John Doe | [email protected] | john123
2 | Jane Doe | [email protected] | jenita123
(2 rows)
myshop=# ALTER TABLE items ADD FOREIGN KEY (category_id) REFERENCES category(id);
ALTER TABLE
myshop=# INSERT INTO users (name) VALUES ('gadget'), ('cloth'),('men'), ('women'),('branded');
INSERT 0 5
myshop=# INSERT INTO items (name, description, price, stock, category_id) VALUES ('Samsung b50', 'hape keren dari merek sumsang', 4000000, 100, 1), ('Uniklooh', 'baju keren dari brand ternama', 500000, 50, 2), ('IMHO Watch','jam tangan anak yang jujur banget', 2000000, 10, 1);
ERROR: insert or update on table "items" violates foreign key constraint "items_category_id_fkey"
DETAIL: Key (category_id)=(1) is not present in table "category".
myshop=# select * from category;
id | name
----+------
(0 rows)
myshop=# select * from users;
id | name | email | password
----+----------+--------------+-----------
1 | John Doe | [email protected] | john123
2 | Jane Doe | [email protected] | jenita123
3 | gadget | |
4 | cloth | |
5 | men | |
6 | women | |
7 | branded | |
(7 rows)
myshop=# INSERT INTO category (name) VALUES ('gadget'), ('cloth'),('men'), ('women'),('branded');
INSERT 0 5
myshop=# INSERT INTO items (name, description, price, stock, category_id) VALUES ('Samsung b50', 'hape keren dari merek sumsang', 4000000, 100, 1), ('Uniklooh', 'baju keren dari brand ternama', 500000, 50, 2), ('IMHO Watch','jam tangan anak yang jujur banget', 2000000, 10, 1);
INSERT 0 3
myshop=# select * from items where price > 1000000;
id | name | description | price | stock | category_id
----+-------------+-----------------------------------+---------+-------+-------------
4 | Samsung b50 | hape keren dari merek sumsang | 4000000 | 100 | 1
6 | IMHO Watch | jam tangan anak yang jujur banget | 2000000 | 10 | 1
(2 rows)
myshop=# select * from items;
id | name | description | price | stock | category_id
----+-------------+-----------------------------------
Aryanti Dwiastuti, [14.02.20 12:02]
+---------+-------+-------------
4 | Samsung b50 | hape keren dari merek sumsang | 4000000 | 100 | 1
5 | Uniklooh | baju keren dari brand ternama | 500000 | 50 | 2
6 | IMHO Watch | jam tangan anak yang jujur banget | 2000000 | 10 | 1
(3 rows)
myshop=# select * from items where name like 'uniklo%';
id | name | description | price | stock | category_id
----+------+-------------+-------+-------+-------------
(0 rows)
myshop=# select * from items where name like 'Uniklo%';
id | name | description | price | stock | category_id
----+----------+-------------------------------+--------+-------+-------------
5 | Uniklooh | baju keren dari brand ternama | 500000 | 50 | 2
(1 row)
myshop=# select * from items where name like 'Watch%';
id | name | description | price | stock | category_id
----+------+-------------+-------+-------+-------------
(0 rows)
myshop=# select * from items where name like '%Watch';
id | name | description | price | stock | category_id
----+------------+-----------------------------------+---------+-------+-------------
6 | IMHO Watch | jam tangan anak yang jujur banget | 2000000 | 10 | 1
(1 row)
myshop=# select * from items where name like '%sang';
id | name | description | price | stock | category_id
----+------+-------------+-------+-------+-------------
(0 rows)
myshop=# select * from items where name like '%sang%';
id | name | description | price | stock | category_id
----+-------------+-------------------------------+---------+-------+-------------
4 | Sumsang b50 | hape keren dari merek sumsang | 4000000 | 100 | 1
(1 row)
myshop=# select * from users;
id | name | email | password
----+----------+--------------+-----------
1 | John Doe | [email protected] | john123
2 | Jane Doe | [email protected] | jenita123
(2 rows)
myshop=# select (name, email) from users;
row
---------------------------
("John Doe",[email protected])
("Jane Doe",[email protected])
(2 rows)
myshop=# UPDATE items SET price = 2500000 where name like 'Sumsang%';
UPDATE 1
myshop=# select * from items;
id | name | description | price | stock | category_id
----+-------------+-----------------------------------+---------+-------+-------------
5 | Uniklooh | baju keren dari brand ternama | 500000 | 50 | 2
6 | IMHO Watch | jam tangan anak yang jujur banget | 2000000 | 10 | 1
4 | Sumsang b50 | hape keren dari merek sumsang | 2500000 | 100 | 1
(3 rows)
myshop=#