Learning machine learning? Try my machine learning flashcards or Machine Learning with Python Cookbook.
Import CSV
Create Table
-- Create table called adventurers
CREATE TABLE adventurers (
-- string variable
name varchar(255),
-- integer variable
age int,
-- string variable
race varchar(255),
-- string variable
weapon varchar(255)
)
Insert Rows
-- Insert into the table adventurers
INSERT INTO adventurers (name, age, race, weapon)
VALUES ('Fjoak Doom-Wife', 28, 'Human', 'Axe'),
('Alooneric Cortte', 29, 'Elf', 'Bow'),
('Piperel Ramsay', 35, 'Elf', 'Sword'),
('Casimir Yardley', 14, 'Elf', 'Magic')
Export To CSV
-- Export the adventurers table to that file path and
-- name using the comma delimiter and with column headings
COPY adventurers TO '/Users/chrisalbon/example_file.csv' DELIMITER ',' CSV HEADER
Create Empty Table
-- Create table called heroes
CREATE TABLE heroes (
-- string variable
name varchar(255),
-- integer variable
age int,
-- string variable
race varchar(255),
-- string variable
weapon varchar(255)
)
Import CSV
-- Import to the heros table the CSV file that uses comma delimiters and has column headers
COPY heroes FROM '/Users/chrisalbon/example_file.csv' DELIMITER ',' CSV HEADER
View Table
-- Get all rows from table
SELECT * FROM heroes
name | age | race | weapon |
---|---|---|---|
Fjoak Doom-Wife | 28 | Human | Axe |
Alooneric Cortte | 29 | Elf | Bow |
Piperel Ramsay | 35 | Elf | Sword |
Casimir Yardley | 14 | Elf | Magic |