Skip to content

Play around with a simple test table

Jennifer Scheuerell edited this page Mar 3, 2020 · 1 revision

Let's begin by checking what tables exist in our database. We haven't made any tables yet so we expect there to be none.

tutorial=# \dt
Did not find any relations.

Ok, let's make a table:

tutorial=# create table test(test_field text);
CREATE TABLE

Let's see if our table is returned when we check the database tables:

tutorial=# \dt
        List of relations
 Schema | Name | Type  |  Owner   
--------+------+-------+----------
 public | test | table | jennifer

Cool. Let's see how big the table is:

tutorial=# \dt+
                      List of relations
 Schema | Name | Type  |  Owner   |    Size    | Description 
--------+------+-------+----------+------------+-------------
 public | test | table | jennifer | 8192 bytes | 
(1 row)

Ok, let's see user a select query to see what is in the table:

tutorial=# select * from test;
 test_field 
------------
(0 rows)

The table is empty. Let's write in some data.

tutorial=# insert into test (test_field) values ('Hello World');
INSERT 0 1

And check again what is in the table:

tutorial=# select * from test;
 test_field  
-------------
 Hello World
(1 row)

Let's change a value in the table:

tutorial=# update test set test_field = test_field || '!';
UPDATE 1

And query the table again:

tutorial=# select * from test;
  test_field  
--------------
 Hello World!
(1 row)

Now let's delete the table.

tutorial=# drop table test;
DROP TABLE

And check that it is really gone:

tutorial=# \dt
Did not find any relations.

Clone this wiki locally