Bootstrap FreeKB - Postgres (SQL) - Create a new table using the psql command
Postgres (SQL) - Create a new table using the psql command

Updated:   |  Postgres (SQL) articles

The psql command with a "create table" statement can be used to create a new table.

If using the default posgres user account, I typically go with the following command.

sudo -u postgres psql --command "create table mytable (id serial primary key not null, date_created date, firstname varchar(30) not null, lastname varchar(50) not null)"

 

If you have created a user account, the -u or --username option and --password flag can be used.

psql --username johndoe --password --command "create table mytable (id serial primary key not null, date_created date, firstname varchar(30) not null, lastname varchar(50) not null)"

 

Better yet, you can setup passwordless authentication using the hidden .pgpass file and then connect without the --password flag.

psql --username johndoe --dbname mydb --command "create table mytable (id serial primary key not null, date_created date, firstname varchar(30) not null, lastname varchar(50) not null)"

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 0a94f0 in the box below so that we can be sure you are a human.