-1
I am having the following error when creating a POSTGRESQL database:
SQL CODE:
CREATE DATABASE pesadaum;
CREATE TABLE user(
user_id int PRIMARY KEY NOT NULL AUTO_INCREMENT,
email varchar(255) NOT NULL,
heavy_pass varchar(255) NOT NULL
);
CREATE TABLE admin_user(
admin_user_id int PRIMARY KEY NOT NULL AUTO_INCREMENT,
email varchar(255) NOT NULL,
heavy_pass varchar(255) NOT NULL,
admin_name varchar(255) NOT NULL,
rg varchar(15) NOT NULL,
cpf varchar(15) NOT NULL,
access_lvl boolean NOT NULL,
);
CREATE TABLE problem(
problem_id int PRIMARY KEY NOT NULL AUTO_INCREMENT,
address point,
description text
user_id int NOT NULL REFERENCES user(user_id)
);
CREATE TABLE img(
img_id int PRIMARY KEY NOT NULL AUTO_INCREMENT,
url varchar(255) NOT NULL,
status_acc boolean,
problem_id int NOT NULL REFERENCES problem_id(problem_id)
);
CREATE TABLE error(
error_id int PRIMARY KEY NOT NULL AUTO_INCREMENT,
error_name varchar(255),
error_description TEXT,
);
CREATE TABLE error_problem_plug(
problem_id int NOT NULL REFERENCES problem(problem_id),
error_id int NOT NULL REFERENCES error(error_id)
);
Only one detail not explicitly mentioned: USER is a reserved keyword in both Postgresql and SQL:2016, SQL:2011 and SQL-92. The way around this is to use "Quoted Identifiers", for example: "user" but in this case you will always have to use quotation marks when referencing this field. Note that for Quoted "user", "USER" and "User" are distinct identifiers, which do not happen with common identifiers: foo, FOO or Foo refer to the same identifier.
– anonimo