Skip to content
Newer
Older
100644 538 lines (307 sloc) 21.8 KB
c66844c @jeremyevans Add Sequel for SQL Users guide
jeremyevans authored
1 = Sequel for SQL Users
2
e30e21e @burningTyger fixed a couple of typos.
burningTyger authored
3 One of the main benefits of Sequel is that it doesn't require the user to know SQL in order to use it, though SQL knowledge is certainly helpful. Unlike most other Sequel documentation, this guide assumes you know SQL, and provides an easy way to discover how to do something in Sequel given the knowledge of how to do so in SQL.
c66844c @jeremyevans Add Sequel for SQL Users guide
jeremyevans authored
4
5 == You Can Just Use SQL
6
7 With Sequel, it's very easy to just use SQL for your queries. If learning Sequel's DSL seems like a waste of time, you are certainly free to write all your queries in SQL. Sequel uses a few different methods depending on the type of query you are doing.
8
9 === SELECT
10
11 For SELECT queries, you should probably use <tt>Database#fetch</tt> with a string and a block:
12
13 DB.fetch("SELECT * FROM albums") do |row|
14 puts row[:name]
15 end
16
17 <tt>Database#fetch</tt> will take the query you give it, execute it on the database, and yield a hash with column symbol keys for each row returned. If you want to use some placeholder variables, you can set the placeholders with ? and add the arguments to fetch:
18
19 DB.fetch("SELECT * FROM albums WHERE name LIKE ?", 'A%') do |row|
20 puts row[:name]
21 end
22
23 You can also use named placeholders by starting the placeholder with a colon, and using a hash for the argument:
24
25 DB.fetch("SELECT * FROM albums WHERE name LIKE :pattern", :pattern=>'A%') do |row|
26 puts row[:name]
27 end
28
29 This can be helpful for long queries where it is difficult to match the ? with the arguments.
30
31 What Sequel actually does internally is two separate things. It first creates a dataset representing the query, and then it executes the dataset's SQL code to retrieve the objects. Often, you want to define a dataset at some point, but not execute it till later. You can do this by leaving off the block, and storing the dataset in a variable:
32
33 ds = DB.fetch("SELECT * FROM albums")
34
e30e21e @burningTyger fixed a couple of typos.
burningTyger authored
35 Then, when you want to retrieve the rows later, you can call +each+ on the dataset to retrieve the rows:
c66844c @jeremyevans Add Sequel for SQL Users guide
jeremyevans authored
36
37 ds.each{|r| puts r[:name]}
38
39 You should note that <tt>Database#[]</tt> calls <tt>Database#fetch</tt> if a string is provided, so you can also do:
40
41 ds = DB["SELECT * FROM albums"]
42 ds.each{|r| puts r[:name]}
43
44 However, note that <tt>Database#[]</tt> cannot take a block directly, you have to call +each+ on the returned dataset. There are plenty of other methods besides +each+, one is +all+ which returns all records as an array:
45
46 DB["SELECT * FROM albums"].all # [{:id=>1, :name=>'RF', ...}, ...]
47
48 === INSERT, UPDATE, DELETE
49
50 INSERT, UPDATE, and DELETE all work the same way. You first create the dataset with the SQL you want to execute using <tt>Database#[]</tt>:
51
52 insert_ds = DB["INSERT INTO albums (name) VALUES (?)", 'RF']
53 update_ds = DB["UPDATE albums SET name = ? WHERE name = ?", 'MO', 'RF']
54 delete_ds = DB["DELETE FROM albums WHERE name = ?", 'MO']
55
56 Then, you call the +insert+, +update+, or +delete+ method on the returned dataset:
57
58 insert_ds.insert
59 update_ds.update
60 delete_ds.delete
61
62 +update+ and +delete+ should return the number of rows affected, and +insert+ should return the autogenerated primary key integer for the row inserted (if any).
63
64 === Other Queries
65
66 All other queries such as TRUNCATE, CREATE TABLE, and ALTER TABLE should be executed using <tt>Database#run</tt>:
67
68 DB.run "CREATE TABLE albums (id integer primary key, name varchar(255))"
69
70 You can also use <tt>Database#<<</tt>:
71
72 DB << "ALTER TABLE albums ADD COLUMN copies_sold INTEGER"
73
74 === Other Places
75
76 Almost everywhere in Sequel, you can drop down to literal SQL by providing a literal string, which you can create with <tt>String#lit</tt>:
77
78 DB[:albums].select('name') # SELECT 'name' FROM albums
79 DB[:albums].select('name'.lit) # SELECT name FROM albums
80
346838e @benarmston Minor corrections to 'Sequel for SQL' users docs
benarmston authored
81 So you can use Sequel's DSL everywhere you find it helpful, and fallback to literal SQL if the DSL can't do what you want or you just find literal SQL easier.
c66844c @jeremyevans Add Sequel for SQL Users guide
jeremyevans authored
82
83 == Translating SQL Expressions into Sequel
84
85 The rest of this guide assumes you want to use Sequel's DSL to represent your query, that you know how to write the query in SQL, but you aren't sure how to write it in Sequel.
86
87 This section will describe how specific SQL expressions are handled in Sequel. The next section will discuss how to create queries by using method chaining on datasets.
88
89 === <tt>Database#literal</tt>
90
91 Before we get started, I think it's important to get familiar with the <tt>Database#literal</tt> method, which will return the SQL that will be used for a given expression:
92
93 DB.literal(1)
94 # => "1"
95 DB.literal(:column)
96 # => "\"column\""
97 DB.literal('string')
98 # => "'string'"
99
100 I encourage you to just play around to see how different objects get literalized into SQL
101
102 === Database Loggers
103
104 Some Sequel methods handle literalization slightly differently than <tt>Database#literal</tt>. If you want to see all SQL queries that Sequel is sending to the database, you should add a database logger:
105
106 DB.loggers << Logger.new($stdout)
107
108 Now that you know how to see what SQL is being used, let's jump in and see how to map SQL syntax to Sequel syntax:
109
110 === Identifiers
111
112 In Sequel, SQL identifiers are usually specified as ruby symbols:
113
114 :column # "column"
115
116 As you can see, Sequel quotes identifiers by default. Depending on your database, it may uppercase them by default as well:
117
118 :column # "COLUMN" on some databases
119
120 A plain symbol is usually treated as an unqualified identifier. However, if you are using multiple tables in a query, and you want to reference a column in one of the tables that has the same name as a column in another one of the tables, you need to qualify that reference. There's two main ways in Sequel to do that. The first is implicit qualification inside the symbol, using the double underscore:
121
122 :table__column # "table"."column"
123
124 Note that you can't use a period to separate them:
125
126 :table.column # calls the column method on the symbol
127
128 Also note that specifying the period inside the symbol doesn't work if you are quoting identifiers:
129
130 :"table.column" # "table.column"
131
132 The other way to qualify an identifier is to use the +qualify+ method on the column symbol with the table symbol:
133
134 :column.qualify(:table) # "table"."column"
135
136 Another way to generate identifiers is to use Sequel's {virtual row support}[link:files/doc/virtual_rows_rdoc.html]:
137
138 DB[:albums].select{name} # SELECT "name" FROM "albums"
139 DB[:albums].select{albums__name} # SELECT "albums"."name" FROM "albums"
140
141 === Numbers
142
143 In general, ruby numbers map directly to SQL numbers:
144
145 # Integers
146 1 # 1
147 -1 # -1
148
149 # Floats
150 1.5 # 1.5
151
152 # BigDecimals
153 BigDecimal.new('1000000.123091029') # 1000000.123091029
154
155 === Strings
156
157 In general, ruby strings map directly to SQL strings:
158
159 'name' # 'name'
160 "name" # 'name'
161
162 === Aliasing
163
164 Sequel allows for implicit aliasing in column symbols using the triple underscore:
165
166 :column___alias # "column" AS "alias"
167
168 You can combine this with implicit qualification:
169
170 :table__column___alias # "table"."column" AS "alias"
171
172 You can also use the +as+ method on symbols and most Sequel-specific expression objects:
173
174 :column.as(:alias) # "column" AS "alias"
175 :column.qualify(:table).as(:alias) # "table"."column" AS "alias"
176
177 === Functions
178
179 The easiest way to use SQL functions is via a virtual row:
180
181 DB[:albums].select{function{}} # SELECT function() FROM "albums"
182 DB[:albums].select{function(col1, col2)} # SELECT function("col1", "col2") FROM "albums"
183
184 You can also use the +sql_function+ method on the symbol that contains the function name:
185
186 :function.sql_function # function()
187 :function.sql_function(:col1, :col2) # function("col1", "col2")
188
189 === Aggregate Functions
190
191 Aggregate functions work the same way as normal functions, since they share the same syntax:
192
193 :sum.sql_function(:column) # sum(column)
194
195 However, if you want to use the DISTINCT modifier to an aggregate function, you either have to use literal SQL or a virtual row block:
196
197 :sum.sql_function('DISTINCT column'.lit) # sum(DISTINCT column)
198 DB[:albums].select{sum(:distinct, :column){}} # SELECT sum(DISTINCT column) FROM albums
199
200 If you want to use the wildcard as the sole argument of the aggregate function, you again have to use literal SQL or a virtual row block:
201
202 :count.sql_function('*'.lit) # count(*)
203 DB[:albums].select{count(:*){}} # SELECT count(*) FROM albums
204
205 Note that Sequel provides helper methods for aggregate functions such as +count+, +sum+, +min+, +max+, +avg+, and +group_and_count+, which handle common uses of aggregate functions.
206
207 === Window Functions
208
209 If the database supports window functions, Sequel can handle them using a virtual row block:
210
211 DB[:albums].select{function(:over){}}
212 # SELECT function() OVER () FROM albums
213
214 DB[:albums].select{count(:over, :*=>true){}}
215 # SELECT count(*) OVER () FROM albums
216
217 DB[:albums].select{function(:over, :args=>col1, :partition=>col2, :order=>col3){}}
218 # SELECT function(col1) OVER (PARTITION BY col2 ORDER BY col3) FROM albums
219
220 DB[:albums].select{function(:over, :args=>[c1, c2], :partition=>[c3, c4], :order=>[c5, c6]){}}
221 # SELECT function(c1, c2) OVER (PARTITION BY c3, c4 ORDER BY c5, c6) FROM albums
222
223 === Equality Operator (=)
224
225 Sequel uses hashes to specify equality:
226
227 {:column=>1} # ("column" = 1)
228
229 You can also specify this as an array of two element arrays:
230
231 [[:column, 1]] # ("column" = 1)
232
233 === Not Equal Operator (!=)
234
235 You can specify a not equals condition by inverting the hash or array of two element arrays using +sql_negate+ or ~:
236
237 {:column => 1}.sql_negate # ("column" != 1)
238 [[:column, 1]].sql_negate # ("column" != 1)
239 ~{:column => 1} # ("column" != 1)
240 ~[[:column, 1]] # ("column" != 1)
241
242 The most common need for not equals is in filters, in which case you can use the +exclude+ method:
243
244 DB[:albums].exclude(:column=>1) # SELECT * FROM "albums" WHERE ("column" != 1)
245
246 === Inclusion and Exclusion Operators (IN, NOT IN)
247
248 Sequel also uses hashes to specify inclusion, and inversions of those hashes to specify exclusion:
249
250 {:column=>[1, 2, 3]} # ("column" IN (1, 2, 3))
251 ~{:column=>[1, 2, 3]} # ("column" NOT IN (1, 2, 3))
252
253 As you may have guessed, Sequel switches from an = to an IN when the hash value is an array. It also does this for datasets, which easily allows you to test for inclusion and exclusion in a subselect:
254
255 {:column=>DB[:albums].select(:id)} # ("column" IN (SELECT "id" FROM "albums"))
256 ~{:column=>DB[:albums].select(:id)} # ("column" NOT IN (SELECT "id" FROM "albums"))
257
258 Sequel also supports the SQL EXISTS operator using <tt>Dataset#exists</tt>:
259
260 DB[:albums].exists # EXISTS (SELECT * FROM albums)
261
262 === Identity Operators (IS, IS NOT)
263
264 Hashes in Sequel use IS if the value is true, false, or nil:
265
266 {:column=>nil) # ("column" IS NULL)
267 {:column=>true) # ("column" IS TRUE)
268 {:column=>false) # ("column" IS FALSE)
269
270 Negation works the same way as it does for equality and inclusion:
271
272 {:column=>nil).sql_negate # ("column" IS NOT NULL)
273 {:column=>true).sql_negate # ("column" IS NOT TRUE)
274 {:column=>false).sql_negate # ("column" IS NOT FALSE)
275
276 === Inversion Operator (NOT)
277
278 Sequel's general inversion operator is ~, which works on symbols and most Sequel-specific expression objects:
279
280 ~:column # NOT "column"
281
282 Note that ~ will actually apply the inversion operation to the underlying object, which is why
283
284 ~{:column=>1}
285
286 produces <tt>(column != 1)</tt> instead of <tt>NOT (column = 1)</tt>.
287
288 === Inequality Operators (< > <= >=)
289
290 Sequel defines the inequality operators directly on most Sequel-specific expression objects:
291
292 :column.qualify(:table) > 1 # ("table"."column" > 1)
293 :column.qualify(:table) < 1 # ("table"."column" < 1)
294 :function.sql_function >= 1 # (function() >= 1)
295 :function.sql_function(:column) <= 1 # (function("column") <= 1)
296
297 If you want to use them on a symbol, you should call +identifier+ on the symbol:
298
299 :column.identifier > 1 # ("column" > 1)
300
301 A common use of virtual rows is to handle inequality operators:
302
303 DB[:albums].filter{col1 > col2} # SELECT * FROM "albums" WHERE ("col1" > "col2")
304
305 === Standard Mathematical Operators (+ - * /)
306
307 The standard mathematical operates are defined on symbol and most Sequel-specific expression objects:
308
309 :column + 1 # "column" + 1
310 :table__column - 1 # "table"."column" - 1
311 :column.qualify(:table) * 1 # "table"."column" * 1
312 :column / 1 # "column" / 1
313
314 Note that the following does not work:
315
316 1 + :column # raises TypeError
317
346838e @benarmston Minor corrections to 'Sequel for SQL' users docs
benarmston authored
318 For commutative operates such as + and *, this isn't a problem as you can just reorder, but non-commutative operators such as - and / cannot be expressed directly. However, Sequel comes with an +sql_expr+ extension that adds an +sql_expr+ method to all objects, allowing you to do:
c66844c @jeremyevans Add Sequel for SQL Users guide
jeremyevans authored
319
320 Sequel.extension :sql_expr
321 1.sql_expr / :column # (1 / "column")
322
323 === Boolean Operators (AND OR)
324
325 Sequel defines the & and | methods on symbols, hashes, and most Sequel-specific expression objects to handle AND and OR:
326
327 :column1 & :column2 # ("column1" AND "column2")
328 {:column1=>1} | {:column2=>2} # (("column1" = 1) OR ("column2" = 2))
329 (:function.sql_function > 1) & :column3 # ((function() > 1) AND "column3")
330
331 Note the use of parentheses in the last statement. If you omit them, you won't get what you expect:
332
333 :function.sql_function > 1 & :column3 # (function() > 1)
334
335 This is because & has higher precedence than >, so it is parsed as:
336
337 :function.sql_function > (1 & :column3)
338
339 In this case, <tt>:column3.to_int</tt> returns an odd integer, so:
340
341 1 & :column3 # => 1
342
343 You can use hashes and arrays of two element arrays to specify AND and OR with equality conditions:
344
345 {:column1=>1, :column2=>2} # (("column1" = 1) AND ("column2" = 2))
346 [[:column1, 1], [:column2, 2]] # (("column1" = 1) AND ("column2" = 2))
347
348 As you can see, these literalize with ANDs by default. You can use the +sql_or+ method to use OR instead:
349
350 {:column1=>1, :column2=>2}.sql_or # (("column1" = 1) OR ("column2" = 2))
351
352 You've already seen the +sql_negate+ method, which will use ANDs if multiple entries are used:
353
354 {:column1=>1, :column2=>2}.sql_negate # (("column1" != 1) AND ("column2" != 2))
355
356 To negate while using ORs, the ~ operator can be used:
357
358 ~{:column1=>1, :column2=>2} # (("column1" != 1) OR ("column2" != 2))
359
360 Note that <tt>Dataset#exclude</tt> uses ~, not +sql_negate+:
361
362 DB[:albums].exclude(:column1=>1, :column2=>2) # SELECT * FROM "albums" WHERE (("column" != 1) OR ("column2" != 2))
363
364 === Casts
365
366 Casting in Sequel is done with the +cast+ method, which is available on strings, symbols, and most of the Sequel-specific expression objects:
367
368 :name.cast(:text) # CAST("name" AS text)
369 '1'.cast(:integer) # CAST('1' AS integer)
370 :column.qualify(:table).cast(:date) # CAST("table"."column" AS date)
371
372 === Bitwise Mathematical Operators (& | ^ << >> ~)
373
374 Sequel allows the use of bitwise mathematical operators on Sequel::SQL::NumericExpression objects:
375
376 :number + 1 # => #<Sequel::SQL::NumericExpression ...>
377 (:number + 1) & 5 # (("number" + 1) & 5)
378
379 As you can see, when you use the + operator on a symbol, you get a NumericExpression. You can turn a symbol into a NumericExpression using +sql_number+:
380
381 :number.sql_number | 5 # ("number" | 5)
382
383 +sql_number+ also works on the many other Sequel-specific expression objects:
384
385 :function.sql_function.sql_number << 7 # (function() << 7)
386 :name.cast(:integer).sql_number >> 8 # (CAST("name" AS integer) >> 8)
387
388 Sequel allows you to do the cast and conversion at the same time via +cast_numeric+:
389
390 :name.cast_numeric ^ 9 # (CAST("name" AS integer) ^ 9)
391
392 Note that &, |, and ~ are already defined to do AND, OR, and NOT on most objects, so if you want to use the bitwise operators, you need to make sure that they are converted first:
393
394 ~:name # NOT "name"
395 ~:name.sql_number # ~"name"
396
397 === String Operators (||, LIKE, Regexp)
398
399 Sequel allows the use of the string concatenation operator on Sequel::SQL::StringExpression objects, which can be created using the +sql_string+ method:
400
401 :name.sql_string + ' - Name' # ("name" || ' - Name')
402
403 Just like for the bitwise operators, Sequel allows you do do the cast and conversion at the same time via +cast_string+:
404
405 :number.cast_string + ' - Number' # (CAST(number AS varchar(255)) || ' - Number')
406
407 Note that similar to the mathematical operators, you cannot switch the order the expression and have it work:
408
409 'Name - ' + :name.sql_string # raises TypeError
410
411 Just like for the mathematical operators, you can use the +sql_expr+ extension to work around this:
412
413 Sequel.extension :sql_expr
414 'Name - '.sql_expr + :name # ('Name - ' || "name")
415
346838e @benarmston Minor corrections to 'Sequel for SQL' users docs
benarmston authored
416 Sequel also adds an <tt>Array#sql_string_join</tt> method, which concatenates all of the elements in the array:
c66844c @jeremyevans Add Sequel for SQL Users guide
jeremyevans authored
417
418 ['Name', :name].sql_string_join # ('Name' || "name")
419
420 Just like ruby's <tt>String#join</tt>, you can provide an argument for a string used to join each element:
421
422 ['Name', :name].sql_string_join(' - ') # ('Name' || ' - ' || "name")
423
424 For the LIKE operator, Sequel defines the +like+ and +ilike+ methods on symbol and most Sequel-specific expression objects:
425
426 :name.like('A%') # ("name" LIKE 'A%')
427 :name.qualify.ilike('A%') # ("name" ILIKE 'A%')
428
429 Note the above syntax, while Sequel's default, is specific to PostgreSQL. However, most other adapters override the behavior. For example, on MySQL, Sequel uses LIKE BINARY for +like+, and LIKE for +ilike+. If the database supports both case sensitive and case insensitive LIKE, then +like+ will use a case sensitive LIKE, and +ilike+ will use a case insensitive LIKE. Some databases only support case insensitive behavior, in which case +like+ and +ilike+ will act identically.
430
431 Inverting the LIKE operator works like other inversions:
432
433 ~:name.like('A%') # ("name" NOT LIKE 'A%')
434
435 Sequel also supports SQL regular expressions on MySQL and PostgreSQL. You can use these by passing a ruby regular expression to the +like+ or +ilike+ method, or by making the regular expression a hash value:
436
437 :name.like(/^A/) # ("name" ~ '^A')
438 ~:name.ilike(/^A/) # ("name" !~* '^A')
439 {:name=>/^A/i} # ("name" ~* '^A')
440 ~{:name=>/^A/} # ("name" !~ '^A')
441
442 Note that using +ilike+ with a regular expression will always make the regexp case insensitive. If you use +like+ or the hash with regexp value, it will only be case insensitive if the Regexp itself is case insensitive.
443
444 === Order Specifications (ASC, DESC)
445
446 Sequel supports specifying ascending or descending order using the +asc+ and +desc+ method on symbols and most Sequel-specific expression objects:
447
448 :column.asc # "column" ASC
449 :column.qualify(:table).desc # "table"."column" DESC
450
451 === All Columns (.*)
452
453 To select all columns in a table, Sequel supports the * method on symbols without an argument:
454
455 :table.* # "table".*
456
457 === CASE statements
458
459 Sequel allows the easy production of SQL CASE statements using the +case+ method of hashes and arrays of two element arrays. The argument to +case+ is the default value, the keys of the hash (or first element in each array) is the WHEN condition, and the values of the hash (or second element in each array) is the THEN result. Here are some examples:
460
461 {:column=>1}.case(0) # (CASE WHEN "column" THEN 1 ELSE 0 END)
462 [[column, 1]].case(0) # (CASE WHEN "column" THEN 1 ELSE 0 END)
463 {{:column=>nil}=>1}.case(0) # (CASE WHEN (column IS NULL) THEN 1 ELSE 0 END)
464
465 If the hash or array has multiple arguments, multiple WHEN clauses are used:
466
467 {:c=>1, :d=>2}.case(0) # (CASE WHEN "c" THEN 1 WHEN "d" THEN 2 ELSE 0 END)
468 [[:c, 1], [:d, 2]].case(0) # (CASE WHEN "c" THEN 1 WHEN "d" THEN 2 ELSE 0 END)
469
470 If you provide a 2nd argument to CASE, it goes between CASE and WHEN:
471
472 {2=>1, 3=>5}.case(0, :column) # (CASE column WHEN 2 THEN 1 WHEN 3 THEN 5 ELSE 0 END)
473
474 === Subscripts/Array Access ([])
475
476 Sequel supports SQL subscripts using the +sql_subscript+ method on symbols and most Sequel-specific expression objects:
477
478 :column.sql_subscript(3) # column[3]
479 :column.qualify(:table).sql_subscript(3) # table.column[3]
480
481 Just like in SQL, you can use any expression as a subscript:
482
483 :column.sql_subscript(:function.sql_function) # column[function()]
484
485 == Building Queries in Sequel
486
487 In Sequel, the SQL queries are build with method chaining.
488
489 === Creating Datasets
490
491 You generally start by creating a dataset by calling <tt>Dataset#[]</tt> with a symbol specifying the table name:
492
493 DB[:albums] # SELECT * FROM albums
494
495 If you want to select from multiple FROM tables, use multiple arguments:
496
497 DB[:albums, :artists] # SELECT * FROM albums, artists
498
499 If you don't want to select from any FROM tables, use no arguments:
500
501 DB[] # SELECT *
502
503 === Chaining Methods
504
505 Once you have your dataset object, you build queries by chaining methods, usually with one method per clause in the query:
506
507 DB[:albums].select(:id, :name).where(:name.like('A%')).order(:name)
508 # SELECT id, name FROM albums WHERE (name LIKE 'A%') ORDER BY name
509
510 Note that the order of your method chain is not usually important unless you have multiple methods that affect the same clause:
511
512 DB[:albums].order(:name).where(:name.like('A%')).select(:id, :name)
513 # SELECT id, name FROM albums WHERE (name LIKE 'A%') ORDER BY name
514
515 === Using the Same Dataset for SELECT, INSERT, UPDATE, and DELETE
516
517 Also note that while the SELECT clause is displayed when you look at a dataset, a Sequel dataset can be used for INSERT, UPDATE, and DELETE as well. Here's an example:
518
519 ds = DB[:albums]
520 ds.all # SELECT * FROM albums
521 ds.insert(:name=>'RF') # INSERT INTO albums (name) VALUES ('RF')
522 ds.update(:name=>'RF') # UPDATE albums SET name = 'RF'
523 ds.delete # DELETE FROM albums
524
525 In general, the +insert+, +update+, and +delete+ methods use the appropriate clauses you defined on the dataset:
526
527 ds = DB[:albums].filter(:id=>1)
528 ds.all # SELECT * FROM albums WHERE (id = 1)
529 ds.insert(:name=>'RF') # INSERT INTO albums (name) VALUES ('RF')
530 ds.update(:name=>'RF') # UPDATE albums SET name = 'RF' WHERE (id = 1)
531 ds.delete # DELETE FROM albums WHERE (id = 1)
532
533 Note how +update+ and +delete+ used the +filter+ argument, but that +insert+ did not, because INSERT doesn't use a WHERE clause.
534
535 === Methods Used for Each SQL Clause
536
537 To see which methods exist that affect each SQL clause, see the {"Dataset Basics" guide}[link:files/doc/dataset_basics_rdoc.html].
Something went wrong with that request. Please try again.