I am trying to create a table in a PSQL database with VSCode, but I receive syntax error. INT is underlined by vscode, if I delete it then TEXT and so on... Could you please give me any idea what is the issue?
CREATE TABLE nfl_week_three (
rank INT,
team TEXT,
games INT,
points_scored INT,
total_yards INT,
offensive_plays INT,
yards_per_play DOUBLE PRECISION,
turnover_lost INT,
fumbles_lost INT,
1st_downs INT,
passes_completed INT,
passes_attempted INT,
passing_yards INT,
passing_touchdowns INT,
passing_interceptions INT,
net_yards_per_passing_attempt DOUBLE PRECISION,
passing_1st_downs INT,
rushing_attempts INT,
rushing_yards INT,
rushing_touchdowns INT,
rushing_yards_per_attempt DOUBLE PRECISION,
rushing_1st_downs INT,
penalties INT,
penalty_yards INT,
1st_down_penalties INT,
percetage_scoring_drives INT,
percentage_turnover_drives INT,
expected_points INT
);
CodePudding user response:
https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS says:
SQL identifiers and key words must begin with a letter (a-z, but also letters with diacritical marks and non-Latin letters) or an underscore (_). Subsequent characters in an identifier or key word can be letters, underscores, digits (0-9), or dollar signs ($).
This means your column name 1st_downs
and others that start with a digit are a problem.
You can either change the column names, or else delimit such names in double-quotes.
CodePudding user response:
You just had some extra 1's in there as typo.
CREATE TABLE nfl_week_three
(
rank INT,
team TEXT,
games INT,
points_scored INT,
total_yards INT,
offensive_plays INT,
yards_per_play DOUBLE PRECISION,
turnover_lost INT,
fumbles_lost INT,
st_downs INT,
passes_completed INT,
passes_attempted INT,
passing_yards INT,
passing_touchdowns INT,
passing_interceptions INT,
net_yards_per_passing_attempt DOUBLE PRECISION,
passing_1st_downs INT,
rushing_attempts INT,
rushing_yards INT,
rushing_touchdowns INT,
rushing_yards_per_attempt DOUBLE PRECISION,
rushing_1st_downs INT,
penalties INT,
penalty_yards INT,
st_down_penalties INT,
percetage_scoring_drives INT,
percentage_turnover_drives INT,
expected_points INT
);