text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
So let's try doing that
here, taking a CSV like this | 1,354.17 | 3.56 |
and adding it to our database. | 1,357.73 | 2.88 |
I'll come back to my computer. | 1,360.61 | 1.99 |
And at this point, I want to start over. | 1,362.6 | 3.27 |
Let's say, I didn't use
[? insert ?] at all. | 1,365.87 | 2.72 |
I actually got a CSV from the MFA
of all the items in our collection. | 1,368.59 | 3.97 |
So I'll type .quit to
leave this database. | 1,372.56 | 2.78 |
And now, I'll type rm mfa.db to
remove this file all together. | 1,375.34 | 5.7 |
Now, let me show you mfa.csv, the
CSV file I have that looks exactly | 1,381.04 | 6.03 |
like what we just saw. | 1,387.07 | 1.41 |
I'll type code mfa.csv. | 1,388.48 | 2.82 |
And now I can indeed see, I
have an iD column, a title | 1,391.3 | 4.14 |
column, and accession_number,
and the date these pieces were | 1,395.44 | 3.39 |
acquired all separated by commas. | 1,398.83 | 3.76 |
So let's say I want to quickly import
this data into its very own database | 1,402.59 | 5.69 |
to run [? SQL ?] [? queries ?] on it. | 1,408.28 | 1.77 |
As it stands, I can't use [? SQL ?]
[? queries ?] on this table | 1,410.05 | 3.15 |
because it's not inside
of a SQLite database. | 1,413.2 | 2.91 |
But let me add one. | 1,416.11 | 1.26 |
I'll type SQLite3 mfa.db to
remake [? MFA ?] down below. | 1,417.37 | 6.1 |
Let me now introduce this new
command that is not a SQL keyword, | 1,423.47 | 4.55 |
but is actually a SQLite command. | 1,428.02 | 2.38 |
And this command is called .import. | 1,430.4 | 3.77 |
.import lets you take
a file, like a CSV, | 1,434.17 | 3.39 |
and automatically insert it row by row
into a table of your own making or one | 1,437.56 | 6.45 |
you can let SQLite create for you. | 1,444.01 | 2.58 |
Let's actually create
the table ourselves, | 1,446.59 | 2.07 |
and then insert this CSV using .import. | 1,448.66 | 3.42 |
So I'll go back to SQLite. | 1,452.08 | 1.91 |
Let me recreate the schema. | 1,453.99 | 1.84 |
Right now, there's no tables inside
this database, but let me create one. | 1,455.83 | 4.66 |
I'll instead type .read schema.sql
to read in that old schema.sql file, | 1,460.49 | 5.75 |
so I can have my own table here. | 1,466.24 | 2.22 |
I'll type that schema again. | 1,468.46 | 1.54 |
And now I see, I have that table back. | 1,470 | 3.15 |
But if I type SELECT [? star ?]
FROM "collections" semicolon, | 1,473.15 | 4.94 |
nothing is inside. | 1,478.09 | 1.89 |
Well, I could fix this. | 1,479.98 | 1.09 |
I could to import this CSV into
collections to insert all at once from | 1,481.07 | 5.15 |
[? its ?] [? own, ?] from the
CSV file we have right here. | 1,486.22 | 3.13 |
So to do this, let me type .import. | 1,489.35 | 3.56 |
Now before I finish this off, there are
a few arguments or options I can give | 1,492.91 | 6.36 |
.import to make sure it works properly. | 1,499.27 | 3.39 |
The ones for this look as follows. | 1,502.66 | 2.77 |
I should type .import, and then
[? dash ?] [? dash ?] CSV to say | 1,505.43 | 5.3 |
I'm importing a CSV. | 1,510.73 | 1.83 |
If I don't type
[? dash ?] [? dash ?] CSV, | 1,512.56 | 3.06 |
SQLite I might assume something
about this file that just isn't true. | 1,515.62 | 3.42 |
It should know that numbers
are here separated by commas, | 1,519.04 | 3.45 |
[? numbers, ?] or [? values, ?]
whatever's inside my table are | 1,522.49 | 2.64 |
separated by commas. | 1,525.13 | 2.17 |
And then [? dash ?] [? dash ?] skip 1-- | 1,527.3 | 2.54 |
well, let's take a look. | 1,529.84 | 1.23 |
If I go back to this
file here, let's see. | 1,531.07 | 3.21 |
I have the first row, the second
row, the third row, the fourth row. | 1,534.28 | 4.62 |
Are there any rows I probably
shouldn't insert into my table here? | 1,538.9 | 5.015 |
Let me ask the audience. | 1,543.915 | 1 |
You're free to raise your hand. | 1,544.915 | 1.545 |
Are there any rows I shouldn't
insert into this table? | 1,546.46 | 3.315 |
Let's go to [? Sukanya. ?] | 1,552.97 | 1.35 |
SPEAKER 5: Yes, I think they
shouldn't include the first one, | 1,554.32 | 3.09 |
because it doesn't give
us any value that we need. | 1,557.41 | 2.5 |
SPEAKER 1: Yeah, you're right. | 1,559.91 | 0.54 |
So if I look at this
header row, as we call it, | 1,560.45 | 2.18 |
I see id, title, accession_number, and
acquired-- the names for my columns. | 1,562.63 | 5.67 |
But notice in my schema, I already
have those column names existing. | 1,568.3 | 4.62 |
So I shouldn't insert the
value id into my "id" column. | 1,572.92 | 4.92 |
I want to just skip that row
and only do the next one. | 1,577.84 | 3.22 |
So here by typing [? dash ?] [? dash ?]
skip 1, I'll skip that header row. | 1,581.06 | 4.82 |
So let's try this now. | 1,585.88 | 1.02 |
I'll say .import
[? dash ?] [? dash ?] CSV. | 1,586.9 | 2.52 |
I'm going to import a CSV. | 1,589.42 | 1.874 |
Now, [? dash ?] [? dash ?] skip,
how many rows should I skip? | 1,591.294 | 3.346 |
Well, just one, the header row there. | 1,594.64 | 2.4 |
Now, I say the file to import. | 1,597.04 | 2.46 |
So I'll type mfa.csv, the CSV
file to import into my database. | 1,599.5 | 5.46 |
Now, I type the name of the
table I'm importing into, | 1,604.96 | 4.08 |
collections, in this case. | 1,609.04 | 1.99 |
And notice how I no longer need to
[? quote ?] collections or [? quote ?] | 1,611.03 | 5.03 |
CSV, because this is not a SQL
statement this is a SQLite statement, | 1,616.06 | 5.448 |
so I can get away with not
[? quoting ?] anything here. | 1,621.508 | 2.292 |
Now, I'll hit Enter. | 1,623.8 | 2.01 |
And again, nothing seems to happen,
but it's probably a good sign. | 1,625.81 | 2.76 |
Let me try selecting [? star ?]
[? from ?] "collections" semicolon, | 1,628.57 | 5.67 |
Enter. | 1,634.24 | 0.9 |
And now all my data is
just magically in there. | 1,635.14 | 2.82 |
It's went from my CSV
into my very own table. | 1,637.96 | 5.943 |
OK, so that's a pretty
nice step forward. | 1,643.903 | 3.687 |
No longer do we have to use
just single line inserts or even | 1,647.59 | 3.51 |
bulk inserts, those multi-line inserts. | 1,651.1 | 2.43 |
We can now just import an
entire table from a CSV. | 1,653.53 | 4.26 |
But I think I've been showing you a
bit of an inaccuracy here, at least | 1,657.79 | 4.29 |
that's not often going to happen to you. | 1,662.08 | 2.4 |
If I go back to this
file here, this CSV. | 1,664.48 | 4.8 |
What you might notice is that
I specified the primary key. | 1,669.28 | 4.2 |
I said [? id ?] of 1,
[? id ?] of 2, [? id ?] of 3. | 1,673.48 | 3.99 |
But if we'd heard before, this
might not be the best design. | 1,677.47 | 3.72 |
Because what if I import
this CSV, and there's already | 1,681.19 | 3.42 |
an item that has the id
of [? 1 ?] or the id of 2. | 1,684.61 | 3.21 |
Ideally, I could let SQLite
create its very own primary keys | 1,687.82 | 4.2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.