HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

LIKE search in bytea datatype (PostgreSQL)

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgresqldatatypesearchbytealike

Problem

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?

Solution

Maybe you can use position function https://www.postgresql.org/docs/13/functions-binarystring.html

WHERE position('csv'::bytea in "blob"."content") > 0

Code Snippets

WHERE position('csv'::bytea in "blob"."content") > 0

Context

StackExchange Database Administrators Q#220130, answer score: 4

Revisions (0)

No revisions yet.