Brackets (not "quotation marks") as a result are decorators for string literals. You are building an array of whole rows (which contain only one column). Instead, only aggregate the column .
In addition, directly building an array from a query result is usually simpler and faster:
SELECT ARRAY ( SELECT e.id FROM public."Esns" e JOIN public."PurchaseOrderItems" p ON p.id = e."PurchaseOrderItemId" WHERE p."GradeId" = 2
You need something ORDER BY if you want a stable result and / or select specific rows. Otherwise, the result will be arbitrary and may change with each subsequent call.
During this, I rewrote the request with explicit JOIN syntax, which is usually preferable, and used rable aliases to simplify.
source share