postgresqlcolumn-alias

PostgreSQL - Escape single quote in an column alias


How to escape single quote in an column alias in PostgreSQL?

I tried several syntaxes without success:

SELECT 'Test 1' AS 'O''Connell';

SELECT 'Test 2' AS 'O\'Connell';

SELECT 'Test 3' AS "O''Connell";

PgAdmin screenshot

pgadmin_screenshot


Solution

  • Use double quote for the identifier, and one single quote inside:

    SELECT 'Test 3' AS "O'Connell";
    
     O'Connell
    -----------
     Test 3