mirror of
https://github.com/jbranchaud/til
synced 2026-01-09 18:18:02 +00:00
Add Sets With The Value Command as a postgres til
This commit is contained in:
@@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really
|
|||||||
warrant a full blog post. These are mostly things I learn by pairing with
|
warrant a full blog post. These are mostly things I learn by pairing with
|
||||||
smart people at [Hashrocket](http://hashrocket.com/).
|
smart people at [Hashrocket](http://hashrocket.com/).
|
||||||
|
|
||||||
_332 TILs and counting..._
|
_333 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -180,6 +180,7 @@ _332 TILs and counting..._
|
|||||||
- [Send A Command To psql](postgres/send-a-command-to-psql.md)
|
- [Send A Command To psql](postgres/send-a-command-to-psql.md)
|
||||||
- [Set Inclusion With hstore](postgres/set-inclusion-with-hstore.md)
|
- [Set Inclusion With hstore](postgres/set-inclusion-with-hstore.md)
|
||||||
- [Set A Seed For The Random Number Generator](postgres/set-a-seed-for-the-random-number-generator.md)
|
- [Set A Seed For The Random Number Generator](postgres/set-a-seed-for-the-random-number-generator.md)
|
||||||
|
- [Sets With The Value Command](postgres/sets-with-the-value-command.md)
|
||||||
- [Sleeping](postgres/sleeping.md)
|
- [Sleeping](postgres/sleeping.md)
|
||||||
- [Special Math Operators](postgres/special-math-operators.md)
|
- [Special Math Operators](postgres/special-math-operators.md)
|
||||||
- [String Contains Another String](postgres/string-contains-another-string.md)
|
- [String Contains Another String](postgres/string-contains-another-string.md)
|
||||||
|
|||||||
28
postgres/sets-with-the-value-command.md
Normal file
28
postgres/sets-with-the-value-command.md
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# Sets With The Value Command
|
||||||
|
|
||||||
|
You can concisely create sets of values in PostgreSQL using the `values`
|
||||||
|
command.
|
||||||
|
|
||||||
|
```sql
|
||||||
|
> values (1), (2), (3);
|
||||||
|
column1
|
||||||
|
---------
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
```
|
||||||
|
|
||||||
|
You can even create multiple columns of values.
|
||||||
|
|
||||||
|
```sql
|
||||||
|
> values (1, 'a', true), (2, 'b', false);
|
||||||
|
column1 | column2 | column3
|
||||||
|
---------+---------+---------
|
||||||
|
1 | a | t
|
||||||
|
2 | b | f
|
||||||
|
```
|
||||||
|
|
||||||
|
This is most often used with an insert command, but can be used on its own,
|
||||||
|
as a subquery, within a CTE, etc.
|
||||||
|
|
||||||
|
[source](http://www.postgresql.org/docs/current/static/sql-values.html)
|
||||||
Reference in New Issue
Block a user