This is snippet uses neon as the host, but the host
could easily be an AWS RDS instance, or something else.
psql -h pg.neon.tech
Create a custom type/enum...
-- create pokemon_type enumDROPTYPE"pokemon_type";
DO $$
BEGIN IF NOT EXISTS (SELECT1FROM pg_type WHERE typname ='pokemon_type') THEN
CREATETYPEpokemon_typeas ENUM(
'Bug','Dark','Dragon','Electric',
'Fairy','Fighting','Fire','Flying',
'Ghost','Grass','Ground','Ice',
'Normal','Poison','Psychic','Rock','Steel','Water' );
RAISE NOTICE 'enum "pokemon_type" was created';
ELSE
RAISE WARNING 'enum "pokemon_type" already exists';
END IF;
END
$$;
Create table...
CREATETABLEpokemon.pokemon (
id INTNOT NULL,
name TEXTNOT NULL,
type_1 pokemon_type NOT NULL,
type_2 pokemon_type,
total INTNOT NULL,
hp INTNOT NULL,
attack INTNOT NULL,
defense INTNOT NULL,
sp_atk INTNOT NULL,
sp_def INTNOT NULL,
speed INTNOT NULL,
generation INTNOT NULL,
legendary BOOLEANNOT NULL);
erDiagram
pokemon {
INT id "NOT NULL"
TEXT name "NOT NULL"
pokemon_type type_1 "NOT NULL"
pokemon_type type_2
INT total "NOT NULL"
INT hp "NOT NULL"
INT attack "NOT NULL"
INT defense "NOT NULL"
INT sp_atk "NOT NULL"
INT sp_def "NOT NULL"
INT speed "NOT NULL"
INT generation "NOT NULL"
BOOLEAN legendary "NOT NULL"
}
Copy data from CSV...
# while connected via psql...# arbitrary bash commands\!pwd\! ls
\cd pokemon
\copy pokemon.pokemon FROM './pokemon.csv' DELIMITER ',' CSV HEADER;