Last active
April 24, 2020 14:29
-
-
Save sarahg/b68827332d96a10f66a18c8f509a90c1 to your computer and use it in GitHub Desktop.
List databases, select a database, show tables, show columns in a table, basic query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
┌⚡️ sarahgerman in 📁 ~ | |
└❯ psql | |
psql (12.2) | |
Type "help" for help. | |
sarahgerman=# \l | |
List of databases | |
Name | Owner | Encoding | Collate | Ctype | Access privileges | |
-------------+-------------+----------+---------+-------+----------------------------- | |
dvdrental | sarahgerman | UTF8 | C | C | | |
postgres | sarahgerman | UTF8 | C | C | | |
sarahgerman | sarahgerman | UTF8 | C | C | | |
template0 | sarahgerman | UTF8 | C | C | =c/sarahgerman + | |
| | | | | sarahgerman=CTc/sarahgerman | |
template1 | sarahgerman | UTF8 | C | C | =c/sarahgerman + | |
| | | | | sarahgerman=CTc/sarahgerman | |
(5 rows) | |
sarahgerman=# \c dvdrental | |
You are now connected to database "dvdrental" as user "sarahgerman". | |
dvdrental=# \dt | |
List of relations | |
Schema | Name | Type | Owner | |
--------+---------------+-------+------------- | |
public | actor | table | sarahgerman | |
public | address | table | sarahgerman | |
public | category | table | sarahgerman | |
public | city | table | sarahgerman | |
public | country | table | sarahgerman | |
public | customer | table | sarahgerman | |
public | film | table | sarahgerman | |
public | film_actor | table | sarahgerman | |
public | film_category | table | sarahgerman | |
public | inventory | table | sarahgerman | |
public | language | table | sarahgerman | |
public | payment | table | sarahgerman | |
public | rental | table | sarahgerman | |
public | staff | table | sarahgerman | |
public | store | table | sarahgerman | |
(15 rows) | |
dvdrental=# \d actor | |
Table "public.actor" | |
Column | Type | Collation | Nullable | Default | |
-------------+-----------------------------+-----------+----------+----------------------------------------- | |
actor_id | integer | | not null | nextval('actor_actor_id_seq'::regclass) | |
first_name | character varying(45) | | not null | | |
last_name | character varying(45) | | not null | | |
last_update | timestamp without time zone | | not null | now() | |
Indexes: | |
"actor_pkey" PRIMARY KEY, btree (actor_id) | |
"idx_actor_last_name" btree (last_name) | |
Referenced by: | |
TABLE "film_actor" CONSTRAINT "film_actor_actor_id_fkey" FOREIGN KEY (actor_id) REFERENCES actor(actor_id) ON UPDATE CASCADE ON DELETE RESTRICT | |
Triggers: | |
last_updated BEFORE UPDATE ON actor FOR EACH ROW EXECUTE FUNCTION last_updated() | |
dvdrental=# SELECT * FROM actor LIMIT 10; | |
actor_id | first_name | last_name | last_update | |
----------+------------+--------------+------------------------ | |
1 | Penelope | Guiness | 2013-05-26 14:47:57.62 | |
2 | Nick | Wahlberg | 2013-05-26 14:47:57.62 | |
3 | Ed | Chase | 2013-05-26 14:47:57.62 | |
4 | Jennifer | Davis | 2013-05-26 14:47:57.62 | |
5 | Johnny | Lollobrigida | 2013-05-26 14:47:57.62 | |
6 | Bette | Nicholson | 2013-05-26 14:47:57.62 | |
7 | Grace | Mostel | 2013-05-26 14:47:57.62 | |
8 | Matthew | Johansson | 2013-05-26 14:47:57.62 | |
9 | Joe | Swank | 2013-05-26 14:47:57.62 | |
10 | Christian | Gable | 2013-05-26 14:47:57.62 | |
(10 rows) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment