Reputation: 1432
This is my first time producing a script which I can run through the psql terminal using the -f
option.
My script is as follows:
DROP TABLE if EXISTS piste;
DROP TABLE if EXISTS lift;
DROP TABLE if EXISTS lift_location;
CREATE TABLE piste (
piste_name varchar(30) PRIMARY KEY NOT NULL,
grade varchar(10) NOT NULL,
length decimal NOT NULL,
fall smallint NOT NULL,
open boolean NOT NULL,
);
INSERT INTO piste (name, grade, length, fall, open) VALUES
('test name', 'easy', 3.2, 400, true);
This produces the following error:
psql:create_tables.sql:22: NOTICE: table "piste" does not exist, skipping
DROP TABLE
psql:create_tables.sql:23: NOTICE: table "lift" does not exist, skipping
DROP TABLE
psql:create_tables.sql:24: NOTICE: table "lift_location" does not exist, skipping
DROP TABLE
psql:create_tables.sql:33: ERROR: syntax error at or near ")"
LINE 8: );
^
psql:create_tables.sql:36: ERROR: relation "piste" does not exist
LINE 1: INSERT INTO piste (name, grade, length, fall, open) VALUES
Does anybody know what is causing this? From what I can see, the table "piste" is created before I try to insert so how can it say it does not exist?
Thanks, Chris.
Upvotes: 1
Views: 1757
Reputation: 125214
The comma at the end generates the error message:
open boolean NOT NULL,
The other messages are NOTICEs not errors. They just tell you that they didn't drop the table as they did not exist
Upvotes: 2
Reputation:
This error:
psql:create_tables.sql:33: ERROR: syntax error at or near ")" LINE 8: );
Tells you that the table is not created.
You have a dangling comma ,
inside your create table (after the last column). Remove that and you should be fine.
Upvotes: 3