There is a special escaped string representation in PostgreSQL:
SELECT 'line1' || E'\n' || 'line2' SELECT E'lin 1\nline 2'
Know more: