2

I've used the psql module to create a new database using the following syntax:

CREATE DATABASE fish

I can open the database. However, when I try to create tables or columns it gives me a syntax error for the following message.

CREATE TABLE salmon;

this is the error message:

ERROR:  syntax error at or near ";"
LINE 1: CREATE TABLE species;

I've checked a lot of online postgreSQL resources and they haven't been of much help. To the best of my knowledge, I haven't messed up the syntax. Thanks.

2
  • 1
    You need to specify columns when you create your table, or at least the primary key. Commented Dec 21, 2016 at 11:18
  • 1
    Please read the tutorial in the manual Commented Dec 21, 2016 at 11:46

3 Answers 3

1

you can use this syntax for empty table:

create table salmon();

You must create atleast one column in a table:

CREATE TABLE salmon ( column_name data_type ...........);

Postgres create table link: https://www.postgresql.org/docs/9.1/static/sql-createtable.html

Sign up to request clarification or add additional context in comments.

Comments

0

You can't create an empty table - it must have at least one column. E.g.:

CREATE TABLE salmon (name VARCHAR(10));

Comments

0
  1. psql is not a module. Please read https://www.postgresql.org/docs/current/static/app-psql.html

  2. you odn't open a database - you connect to it.

Establishes a new connection to a PostgreSQL server

  1. https://www.postgresql.org/docs/current/static/sql-createtable.html

{ column_name | ( expression ) }

Either column list (create table a (a int);) or expression (create table b as select now() time_column) is obligatory part.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.