ARRAY[] with \'s is broken?

Started by Rod Taylorover 20 years ago6 messages
#1Rod Taylor
pg@rbt.ca

Can anyone explain what's going on with the slashes?

ssdb=# select version();
version
---------------------------------------------------------------------------
PostgreSQL 8.0.1 on sparc-sun-solaris2.9, compiled by GCC gcc (GCC)
3.4.2
(1 row)

ssdb=# select ARRAY['\\a'];
array
---------
{"\\a"}
(1 row)

ssdb=# select ARRAY['\a'];
array
-------
{a}
(1 row)

ssdb=# select ARRAY['\\\a'];
array
---------
{"\\a"}
(1 row)

--

#2Andrew Dunstan
andrew@dunslane.net
In reply to: Rod Taylor (#1)
Re: ARRAY[] with \'s is broken?

I don't see anything broken. V 7.4.8 shows the same:

andrew=# select ARRAY['\\a'] as f1, ARRAY['\a']as f2 , ARRAY['\\\a'] as f2;

f1 | f2 | f2

--------+-----+---------

{"\\a"} | {a} | {"\\a"}

It might be mildly confusing because '\a' == 'a'

cheers

andrew

Rod Taylor wrote:

Show quoted text

Can anyone explain what's going on with the slashes?

ssdb=# select version();
version
---------------------------------------------------------------------------
PostgreSQL 8.0.1 on sparc-sun-solaris2.9, compiled by GCC gcc (GCC)
3.4.2
(1 row)

ssdb=# select ARRAY['\\a'];
array
---------
{"\\a"}
(1 row)

ssdb=# select ARRAY['\a'];
array
-------
{a}
(1 row)

ssdb=# select ARRAY['\\\a'];
array
---------
{"\\a"}
(1 row)

#3Rod Taylor
pg@rbt.ca
In reply to: Andrew Dunstan (#2)
Re: ARRAY[] with \'s is broken?

On Tue, 2005-05-17 at 13:18 -0400, Andrew Dunstan wrote:

I don't see anything broken. V 7.4.8 shows the same:

How the heck do you store a single backslash in an text array?

andrew=# select ARRAY['\\a'] as f1, ARRAY['\a']as f2 , ARRAY['\\\a'] as f2;

f1 | f2 | f2

--------+-----+---------

{"\\a"} | {a} | {"\\a"}

It might be mildly confusing because '\a' == 'a'

cheers

andrew

Rod Taylor wrote:

Can anyone explain what's going on with the slashes?

ssdb=# select version();
version
---------------------------------------------------------------------------
PostgreSQL 8.0.1 on sparc-sun-solaris2.9, compiled by GCC gcc (GCC)
3.4.2
(1 row)

ssdb=# select ARRAY['\\a'];
array
---------
{"\\a"}
(1 row)

ssdb=# select ARRAY['\a'];
array
-------
{a}
(1 row)

ssdb=# select ARRAY['\\\a'];
array
---------
{"\\a"}
(1 row)

--

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Rod Taylor (#3)
Re: ARRAY[] with \'s is broken?

Rod Taylor <pg@rbt.ca> writes:

On Tue, 2005-05-17 at 13:18 -0400, Andrew Dunstan wrote:

I don't see anything broken. V 7.4.8 shows the same:

How the heck do you store a single backslash in an text array?

You just did. array_out doubles the backslashes again, though.

regression=# select ARRAY['\\a'];
array
---------
{"\\a"}
(1 row)

regression=# select (ARRAY['\\a'])[1];
array
-------
\a
(1 row)

regards, tom lane

#5Rod Taylor
pg@rbt.ca
In reply to: Tom Lane (#4)
Re: ARRAY[] with \'s is broken?

How the heck do you store a single backslash in an text array?

... array_out doubles the backslashes again, though.

That explains how I got confused.

regression=# select ARRAY['\\a'];
array
---------
{"\\a"}
(1 row)

regression=# select (ARRAY['\\a'])[1];
array
-------
\a
(1 row)

regards, tom lane

--

#6Andrew Dunstan
andrew@dunslane.net
In reply to: Rod Taylor (#3)
Re: ARRAY[] with \'s is broken?

Rod Taylor wrote:

On Tue, 2005-05-17 at 13:18 -0400, Andrew Dunstan wrote:

I don't see anything broken. V 7.4.8 shows the same:

How the heck do you store a single backslash in an text array?

Well, in v 8.0 I use dollar quoting :-)

select ARRAY[$\$];

But as Tom says the text output function will double it.

cheers

andrew