select count(*) from (select "ships"."id", "ships"."timeCreated", "ships"."timeUpdated", "ships"."deleted", "ships"."userId", "ships"."categoryId", "ships"."status", "ships"."type", "ships"."title", "ships"."message", "ships"."name", "ships"."imo", "ships"."buildYear", "ships"."buildYearTo", "ships"."buildPlace", "ships"."flag", "ships"."loa", "ships"."lbp", "ships"."width", "ships"."depth", "ships"."breadth", "ships"."draft", "ships"."draftTo", "ships"."freeboard", "ships"."grt", "ships"."grtTo", "ships"."nrt", "ships"."dwt", "ships"."dwtTo", "ships"."speed", "ships"."price", "ships"."priceTo", "ships"."regionId", "ships"."ddLast", "ships"."ddNext", "ships"."ssLast", "ships"."ssNext", "ships"."mainEngine", "ships"."auxiliaryEngine", "ships"."gear", "ships"."enginePower", "ships"."meUse", "ships"."class", "ships"."hull", "ships"."bulkerType", "ships"."holdType", "ships"."selfPropelled", "ships"."craneCapacity", "ships"."craneRevolved", "ships"."holds", "ships"."crew", "ships"."closeOwner", "ships"."iceClass", "ships"."decks", "ships"."teu", "ships"."passengers", "ships"."cars", "ships"."rent", "ships"."seaRiverClass", "ships"."loaTo", "ships"."currency", "ships"."externalCompanyName", "ships"."externalId", "ships"."externalUrl", "ships"."hasPdf", "ships"."hasRtf", "ships"."locationAddress", "ships"."locationCountry", "ships"."autoAnswer", "ships"."actualDate", "ships"."priceAccepted", "ships"."sold", COALESCE( ( SELECT jsonb_agg(json_build_object('id', "images"."id", 'name', "images"."name", 'originalName', "images"."originalName", 'path', "images"."path")) FROM (
SELECT * FROM "images" AS "images"
WHERE "ships"."id" = "images"."shipId"
ORDER BY "isMain" DESC, "id" ASC
LIMIT 6
) "images"), NULL) AS "images", COALESCE( ( SELECT jsonb_agg("categories".*) FROM (
SELECT * FROM "categories" AS "categories"
WHERE "categories"."id" = "ships"."categoryId"
) "categories"), NULL) AS "categories", COALESCE( ( SELECT jsonb_agg("lang".*) FROM (
SELECT * FROM "lang" AS "lang"
WHERE "lang"."key" = "ships"."name"
) "lang"), NULL) AS "nameLang", COALESCE( ( SELECT jsonb_agg(json_build_object('companyCountry', "users"."companyCountry", 'companyId', "users"."companyId", 'companyName', "users"."companyName", 'firstName', "users"."firstName", 'secondName', "users"."secondName", 'id', "users"."id", 'position', "users"."position", 'product', "users"."product", 'statuses', "users"."statuses")) FROM (
SELECT * FROM "users" AS "users"
WHERE "users"."id" = "ships"."userId"
) "users"), NULL) AS "users" from "public"."ships" where "deleted" = $1 and "sold" = $2 and "type" = $3 and "userId" = $4) as "w" - invalid input syntax for type integer: "n"