Before you can start saving data, you will have to create a table in your PostgreSQL database. Let’s create a table and call it ‘batteries’ for now. You can create a PostgreSQL tale using the ‘CREATE TABLE‘ command. The following table has three columns: model, type, and capacity.
CREATE TABLE batteries ( model varchar(60), type varchar(60), capacity int );
Once you’ve pressed enter, PostgreSQL should have displayed ‘CREATE TABLE‘.
‘varchar(80)’ and ‘int’ are data type declarations. ‘int’ means integer, which is useful for storing numbers (not floating point numbers), and you can use the ‘numeric’ data type to store decimals. ‘varchar(60)’ means variable characters (up to 60 of them, as I defined in brackets). This is useful for fields containing a combination of numbers and letters (for example: strings) which you don’t intend to perform mathematical operations on.
Note: You don’t have to spread your statements out over multiple lines as shown above. You can also type commands on a single line as you see fit. Usually, typing on a single line is perfectly fine for brief statements.