Method: SqlPostgres::Insert#insert
- Defined in:
- lib/sqlpostgres/Insert.rb
#insert(column, value = :no_value) ⇒ Object
Add a column to the statement. This is for all column types except bytea.
- column
-
The column name
- value
-
The value to add. The value is SQL escaped. Should be one of:
-
a String
-
an Integer
-
a Float
-
a Time
-
false
-
true
-
nil
-
a Select
-
:default
-
:no_value
-
Special values:
- a Select
-
The select’s SQL is added in parentheses
- :default
-
Add the SQL keyword “default” to the statement.
- :no_value
-
Do not add a value for this column. This is used when the values are being provided by a Select statement.
Example (simple) ** Example: insert_insert
insert = Insert.new('foo')
insert.insert('t', 'bar')
p insert.statement # "insert into foo (t) values (E'bar')"
**
Example (select) ** Example: insert_insert_select
select = Select.new
select.select('j')
select.from('bar')
select.limit(1)
insert = Insert.new('foo')
insert.insert('i', select)
p insert.statement # "insert into foo (i) values ((select j
# from bar limit 1))"
**
Example (default) ** Example: insert_insert_default
insert = Insert.new('foo')
insert.insert('i', :default)
p insert.statement # "insert into foo (i) values
# (default)"
**
88 89 90 91 |
# File 'lib/sqlpostgres/Insert.rb', line 88 def insert(column, value = :no_value) @columns << column @values << Translate.escape_sql(value) unless value == :no_value end |