ERROR: syntax error at or near "AND" LINE 1: ...RE paflvend != '' AND CAST(pk.pacodpac AS INT) = AND pk.pat... ^