Re: output a single and double quote in a string - Mailing list pgsql-novice

From Michael Fuhr
Subject Re: output a single and double quote in a string
Date
Msg-id 20050319025641.GA89923@winnie.fuhr.org
Whole thread Raw
In response to Re: output a single and double quote in a string  (George Weaver <gweaver@shaw.ca>)
List pgsql-novice
On Fri, Mar 18, 2005 at 05:13:32PM -0600, George Weaver wrote:
>
> SELECT length_ft::text || chr(39)
>        length_in::text || \' " \' AS length_dim,
>        width_ft::text || chr(39) ||
>        width_in::text || \' " \' AS width_dim
>   FROM sales_order.tbl_net_production;

Not quite -- that produces errors because of a missing || operator
and single quotes that shouldn't be escaped (at least not in a
standalone query).  Perhaps you meant this:

SELECT length_ft::text || chr(39) ||
       length_in::text || '"' AS length_dim,
       width_ft::text || chr(39) ||
       width_in::text || '"' AS width_dim
  FROM sales_order.tbl_net_production;

Other examples:

SELECT '\'' AS single_quote, '"' AS double_quote;
SELECT '''' AS single_quote, '"' AS double_quote;
SELECT $$'$$ AS single_quote, $$"$$ AS double_quote;  -- 8.0 and later

See "String Constants" in the "SQL Syntax" chapter of the documentation:

http://www.postgresql.org/docs/8.0/interactive/sql-syntax.html#SQL-SYNTAX-CONSTANTS

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

pgsql-novice by date:

Previous
From: Sean Davis
Date:
Subject: Re: Best way to input data
Next
From: George Weaver
Date:
Subject: Re: output a single and double quote in a string