Table:
\d blob
Column | Type | Collation | Default
---------+--------------+-----------+------------------------------------------
id | integer | | nextval('modlink_blob_id_seq'::regclass)
content | bytea | |
This statement:
SELECT COUNT(*) "job" INNER JOIN "blob" ON ("job"."input_id" = "blob"."id")
WHERE UPPER("blob"."content"::text) LIKE UPPER('%csv%');
Error message:
ERROR: invalid memory alloc request size 1989028364
What can I do to make this statement not fail?
3 Answers 3
Maybe you can use position function https://www.postgresql.org/docs/13/functions-binarystring.html
WHERE position('csv'::bytea in "blob"."content") > 0
The best way i found to make 'LIKE' search in PostgreSQL in columns with a lot of content was using tsvector columns.
One advantages is more fast than make 'like' searches and allow create index.
The boring part is create a trigger to replicate the content in a new column.
The article below shows how to use tsvector.
http://rachbelaid.com/postgres-full-text-search-is-good-enough/
Column | Type | Collation | Default
---------+--------------+-----------+------------------------------------------
id | integer | | nextval('modlink_blob_id_seq'::regclass)
content | bytea | |
search | tsvector | |
This is the SQL
SELECT COUNT(*) FROM "job" INNER JOIN "blob" ON ("job"."input_id" = "blob"."id")
WHERE blob.search @@ plainto_tsquery('csv');
A observation: I use text
columns instead bytea
.
-
you could setup
search
as agenerate stored
column, right?Tobi– Tobi2021年03月27日 14:27:43 +00:00Commented Mar 27, 2021 at 14:27
ENCODE(content, 'escape')
converts the bytea to text so you can then just continue with
WHERE UPPER(ENCODE(content, 'escape')) LIKE UPPER('%csv%')
bytea
column? That makes no sense. Atext
column would be a lot easier to deal with