I'm trying to run this script with the command "\ i c: /users/public/giro_d'italia2014.sql" as I did with other scripts only that this time sql seems not to do something right ...
this is what it says: unterminated quoted string
\ i: missing required argument ..... I tried to look for this problem but I could not find anything .... can you help me please?
this is the script ...
DROP SCHEMA IF EXISTS giro_d'italia2014 CASCADE;
CREATE SCHEMA giro_d'italia2014;
SET search_path TO giro_d'italia2014;
CREATE TABLE ciclista(
id_ciclista INTEGER PRIMARY KEY,
nome ciclista VARCHAR ,
squadra CHAR(3),
nazione CHAR(3));
CREATE TABLE tappa(
nome_tappa VARCHAR PRIMARY KEY,
km INT,
tipologia {'pianeggiante'|'alta montagna'|'media montagna'|'cronometro a squadre'|'cronometro individuale'|'cronoscalata'} );
CREATE TABLE ordine_arrivo(
id_ciclista INT,
nome_tappa VARCHAR ,
ordine INT,
PRIMARY KEY (id_ciclista, nome_tappa));
You can't include a single quote ' in an identifier unless you use double quotes:
DROP SCHEMA IF EXISTS "giro_d'italia2014" CASCADE;
CREATE SCHEMA "giro_d'italia2014";
SET search_path TO "giro_d'italia2014";
But I strongly recommend to use identifiers that do not need to be quoted.
this
tipologia {'pianeggiante'|'alta montagna'|'media montagna'|'cronometro a squadre'|'cronometro individuale'|'cronoscalata'} );
is also invalid SQL. I don't know what you are trying to achieve with that. if you are trying to limit the values that are allowed, use a check constraint:
(
...
tipologia text not null,
check tipologia in ('pianeggiante', 'alta montagna', 'media montagna', 'cronometro a squadre', 'cronometro individuale', 'cronoscalata')
);
The use of the char data type is also discouraged
Related
CREATE type recommendation as object(
descriptions varchar2(200)
);
create type recomand as table of recommendation;
create type traitement_type as object (
id_traitement number(7),
duree varchar2(25),
recome recomand,
description varchar2(250)
);
CREATE TABLE Traitement (primary key(id_traitement))
nested table recome store as Les_recommendations;
i execute these commands and at the last query i got the error :
ORA-00904: : invalid identifier
any solutions ?
Your create table statement doesn't include a column list. It's interpreting "primary key" a column and spaces are not allowed. Look up the proper format for create table statements and PK constraints.
I have a primary key column in my SQL table in PostgreSQL named "id". It is a "bigseries" column. I want to convert the column to a "UUID" column. It entered the below command in the terminal:
alter table people alter column id uuid;
and
alter table people alter column id uuid using (uuid_generate_v4());
but neither of them worked.
In both tries I got the error message
ERROR: syntax error at or near "uuid"
LINE 1: alter table people alter column id uuid using (uuid_generate...
What is the correct syntax?
First of all uuid_generate_v4() is a function which is provided by an extension called uuid-ossp. You should have install that extension by using;
CREATE EXTENSION uuid-ossp;
Postgresql 13 introduced a new function which does basically the same without installing extension. The function is called gen_random_uuid()
Suppose that we have a table like the one below;
CREATE TABLE people (
id bigserial primary key,
data text
);
The bigserial is not a real type. It's a macro which basically creates bigint column with default value and a sequence. The default value is next value of that sequence.
For your use case, to change data type, you first should drop the old default value. Then, alter the type and finally add new default value expression. Here is the sample:
ALTER TABLE people
ALTER id DROP DEFAULT,
ALTER id TYPE uuid using (gen_random_uuid() /* or uuid_generate_v4() */ ),
ALTER id SET DEFAULT gen_random_uuid() /* or uuid_generate_v4() */ ;
CREATE TABLE IF NOT EXISTS people (
id uuid NOT NULL CONSTRAINT people_pkey PRIMARY KEY,
address varchar,
city varchar(255),
country varchar(255),
email varchar(255),
phone varchar(255)
);
This is the correct syntax to create table in postgres SQL, it's better to do these constraints at beginning to avoid any error.
For using alter command you would do the following:
ALTER TABLE customer ADD COLUMN cid uuid PRIMARY KEY;
Most of errors that you could find while writing command either lower case or undefined correct the table name or column.
I made a script to create a database with PostgreSQL.
So I copy in my script, click "Analyze & Explain" in pgAdmin4 and I have no clue why it says I have a syntax error at or near 'INT' on idSituationFamiliale.
I really can't see what's wrong...
--Personnes
--
CREATE TABLE SITUATION_FAMILIALE (
idSituationFamiliale INT NOT NULL,
intituleSituationFamiliale VARCHAR(50) NOT NULL,
PRIMARY KEY(idSituationFamiliale)
);
The query is fine if you RUN it. It is wrong if you EXPLAIN / ANALYZE it.
The doc says that you can explain a CREATE TABLE AS, not a pure CREATE TABLE statement. While the former contains a SELECT statement that can be explained/analyzed, the later has nothing to be explained/analyzed and fails on the 1st field, regardless of its name or type.
You should be using integer as opposed to int.
e.g
--Personnes
--
CREATE TABLE SITUATION_FAMILIALE (
idSituationFamiliale INTEGER NOT NULL,
intituleSituationFamiliale VARCHAR(50) NOT NULL,
PRIMARY KEY(idSituationFamiliale)
);
We were asked to create a database in sqlite3 and then create a table in it. I used this command:
$sqlite3 me5.db
and tried to create a table with this statement:
CREATE TABLE me5.petID(pet id PRIMARY KEY int(3), pet name varchar(10), pet type varchar(10), pet age int(3));
but it says that:
ERROR: near "CREATE" : syntax error
What could I have possible done wrong? Thanks.
try this
CREATE TABLE petID(pet_id int(3) PRIMARY KEY, pet_name varchar(10), pet_type varchar(10), pet_age int(3));
you dont have to specify the database name because you're already using it after the command sqlite3 me5.db.
you have spaces in the names of the fields, which is not allowed. so i've put underscores instead of spaces.
use PRIMARY KEY after int(3)
Okay no seriously, if a PostgreSQL guru can help out I'm just getting started.
Basically what I want is a simple table like such:
CREATE TABLE schema.searches
(
search_id serial NOT NULL,
search_query character varying(255),
search_count integer DEFAULT 1,
CONSTRAINT pkey_search_id PRIMARY KEY (search_id)
)
WITH (
OIDS=FALSE
);
I need something like REPLACE INTO for MySQL. I don't know if I have to write my own procedure or something?
Basically:
check if the query already exists
if so, just add 1 to the count
it not, add it to the db
I can do this in my php code but I'd rather all that be done in postgres C engine
You have to add a unique constraint first.
ALTER TABLE schema.searches ADD UNIQUE (search_query);
The insert/replace command looks like this.
INSERT INTO schema.searches(search_query) VALUES ('a search query')
ON CONFLICT (search_query)
DO UPDATE SET search_count = schema.searches.search_count + 1;