mirror of
https://github.com/jbranchaud/til
synced 2026-01-17 14:08:01 +00:00
Compare commits
4 Commits
31b9ef8335
...
a8a4de2447
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a8a4de2447 | ||
|
|
9afe6503ec | ||
|
|
b376f32a67 | ||
|
|
295fe153ad |
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
||||
|
||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||
|
||||
_1523 TILs and counting..._
|
||||
_1525 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -402,6 +402,7 @@ _1523 TILs and counting..._
|
||||
- [Do Something N Times](go/do-something-n-times.md)
|
||||
- [Find Executables Installed By Go](go/find-executables-installed-by-go.md)
|
||||
- [Not So Random](go/not-so-random.md)
|
||||
- [Parse A String Into Individual Fields](go/parse-a-string-into-individual-fields.md)
|
||||
- [Replace The Current Process With An External Command](go/replace-the-current-process-with-an-external-command.md)
|
||||
- [Sleep For A Duration](go/sleep-for-a-duration.md)
|
||||
- [Upgrading From An Older Version On Mac](go/upgrading-from-an-older-version-on-mac.md)
|
||||
@@ -776,6 +777,7 @@ _1523 TILs and counting..._
|
||||
- [Escaping String Literals With Dollar Quoting](postgres/escaping-string-literals-with-dollar-quoting.md)
|
||||
- [Export Query Results To A CSV](postgres/export-query-results-to-a-csv.md)
|
||||
- [Extracting Nested JSON Data](postgres/extracting-nested-json-data.md)
|
||||
- [Fetch Specific Number Of Results](postgres/fetch-specific-number-of-results.md)
|
||||
- [Find Duplicate Records In Table Without Unique Id](postgres/find-duplicate-records-in-table-without-unique-id.md)
|
||||
- [Find Records That Contain Duplicate Values](postgres/find-records-that-contain-duplicate-values.md)
|
||||
- [Find Records That Have Multiple Associated Records](postgres/find-records-that-have-multiple-associated-records.md)
|
||||
|
||||
39
go/parse-a-string-into-individual-fields.md
Normal file
39
go/parse-a-string-into-individual-fields.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# Parse A String Into Individual Fields
|
||||
|
||||
Let's say you're reading in data from a file or otherwise dealing with an
|
||||
arbitrary string of data. If that string has a series of values separated by
|
||||
whitespace, you can parse it into individual fields with
|
||||
[`strings.Fields`](https://pkg.go.dev/strings#Fields).
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
data := "3 5 2 6 7 1 9"
|
||||
fields := strings.Fields(data)
|
||||
|
||||
fmt.Printf("Fields: %v", fields)
|
||||
// [3 5 2 6 7 1 9]
|
||||
}
|
||||
```
|
||||
|
||||
Here is another example where we can see that `strings.Fields` deals with
|
||||
multiple whitespace and surrounding whitespace:
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
data := " go java c++ rust "
|
||||
fields := strings.Fields(data)
|
||||
|
||||
fmt.Printf("%v", fields)
|
||||
// [go java c++ rust]
|
||||
}
|
||||
```
|
||||
@@ -5,6 +5,8 @@ an array-like object with all of the arguments to the function. Even if not
|
||||
all of the arguments are referenced in the function signature, they can
|
||||
still be accessed via the `arguments` object.
|
||||
|
||||
> For ES6+ compatibility, the `spread` operator used via [rest parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters) is preferred over the `arugments` object when accessing an abritrary number of function arguments.
|
||||
|
||||
```javascript
|
||||
function argTest(one) {
|
||||
console.log(one);
|
||||
|
||||
42
postgres/fetch-specific-number-of-results.md
Normal file
42
postgres/fetch-specific-number-of-results.md
Normal file
@@ -0,0 +1,42 @@
|
||||
# Fetch Specific Number Of Results
|
||||
|
||||
If you pull up just about any intro to PostgreSQL (or even SQL), one of the
|
||||
first things they are going to teach you is the `limit` clause. This is taught
|
||||
as _the_ way for limiting the result set to a specific number of rows.
|
||||
|
||||
```sql
|
||||
> select title from books limit 4;
|
||||
+-----------------------+
|
||||
| title |
|
||||
|-----------------------|
|
||||
| The Secret History |
|
||||
| A Gentleman in Moscow |
|
||||
| Exhalation: Stores |
|
||||
| Annihilation |
|
||||
+-----------------------+
|
||||
SELECT 4
|
||||
```
|
||||
|
||||
You might be as surprised as I was to learn that `limit` is not part of the SQL
|
||||
standard. It is extremely common for this use case, but the SQL standard
|
||||
defines `fetch first N rows only` as the way to fetch a specific number of
|
||||
rows. As we can see, [it works identically to `limit
|
||||
N`](https://www.postgresql.org/docs/current/sql-select.html#SQL-LIMIT).
|
||||
|
||||
```sql
|
||||
> select title from books fetch first 4 rows only;
|
||||
+-----------------------+
|
||||
| title |
|
||||
|-----------------------|
|
||||
| The Secret History |
|
||||
| A Gentleman in Moscow |
|
||||
| Exhalation: Stores |
|
||||
| Annihilation |
|
||||
+-----------------------+
|
||||
SELECT 4
|
||||
```
|
||||
|
||||
The `rows` and `row` keywords are interchangeable which makes statements more
|
||||
readable if, for instance, you're doing `... fetch first 1 row only`.
|
||||
|
||||
[source](https://www.cybertec-postgresql.com/en/postgresql-limit-vs-fetch-first-rows-with-ties/)
|
||||
Reference in New Issue
Block a user