Skip to content

add: csv_read function - #14

Merged
steve-chavez merged 1 commit into
PostgREST:masterfrom
steve-chavez:csv_read
Aug 17, 2026
Merged

add: csv_read function#14
steve-chavez merged 1 commit into
PostgREST:masterfrom
steve-chavez:csv_read

Conversation

@steve-chavez

@steve-chavez steve-chavez commented Aug 17, 2026

Copy link
Copy Markdown
Member

The csv_read(anyelement, text) function can read inline text values, respecting quoting and escaping inside quotes.

select id, name
from csv_read(null::projects, E'1,IOS,4\n2,"Win""dows",4') where id = 2;
 id |   name
----+----------
  2 | Win"dows

This allows for greater flexibility, csv_read can be combined with pg_read_file, inserts, limit/offset, etc.

Notes

  • For performance it uses SIMD parsing (via cparsec.h, which uses memchr) and avoids pallocing in the hot path (see csv_slice_to_cstr, which is a bit of a trick).
  • Performance is checked by comparing to COPY CSV over a 1M rows parse, this is included in the bench tests.

@steve-chavez steve-chavez mentioned this pull request Aug 17, 2026
1 task
@steve-chavez
steve-chavez marked this pull request as ready for review August 17, 2026 04:44
The `csv_read(anyelement, text)` function can read inline text values, respecting quoting and escaping inside quotes.

```sql
select id, name
from csv_read(null::projects, E'1,IOS,4\n2,"Win""dows",4') where id = 2;
 id |   name
----+----------
  2 | Win"dows
```

This allows for greater flexibility, csv_read can be combined with
pg_read_file, inserts, limit/offset, etc.

Notes
-----

- For performance it uses SIMD parsing (via cparsec.h, which uses memchr) and avoids pallocing in
  the hot path (see `csv_slice_to_cstr`, which is a bit of a trick).
- Performance is checked by comparing to COPY CSV, this is included in
  the bench tests.
@steve-chavez
steve-chavez merged commit a3151af into PostgREST:master Aug 17, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant