Thread: Can || be used in ORDER BY?

Can || be used in ORDER BY?

From
"Jeremy Malcolm"
Date:
-----BEGIN PGP SIGNED MESSAGE-----

I would like to do this:

                        select
                        field1,field2
                        from tablename
                        order by (field1||'-top')

ie. order the records by the contents of field1 with the text "-top"
concatenated to it.  It doesn't work, I get a parse error.

Can anyone offer advice?

Thanks.

- --
JEREMY MALCOLM Jeremy@Malcolm.wattle.id.au http://malcolm.wattle.id.au
SIG of the day: [ ] Contact  [ ] Web  [ ] PGP  [ ] Taglines #1  [x] #2
"I'm a lawyer." "Honest?" "No, the usual kind." | Linux, the choice of
a GNU generation. | Are you the brain specialist? | "Could anyone pass
the sodium chloride, please?" - Adric (5W) | The Nanites have lawyers?

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.0.2i

iQB1AwUBOI3a6L/mBljD2JABAQG3RQL8DxUkukKGm7jEa9rSgyFzXMcd5KJejRxU
abscA8SuVq7ENXdFncx+5OsAk0VQfzBkUkRlobD9LEFXm6aTsK2zqmlhdVsJFKyh
f/YOixdaGiNzE+9xfIpEz+iizzKBwPRy
=bED8
-----END PGP SIGNATURE-----


Re: [GENERAL] Can || be used in ORDER BY?

From
Jose Soares
Date:
create table tablename ( field1 text, field2 text);
CREATE
insert into tablename values('bottom','yes');
INSERT 2282464 1
insert into tablename values('top','no');
INSERT 2282465 1
select field1,field2 from tablename order by (field1||'-top');

field1|field2
------+------
bottom|yes
top   |no
(2 rows)
 

José
 

Jeremy Malcolm wrote:

-----BEGIN PGP SIGNED MESSAGE-----

I would like to do this:

                        select
                        field1,field2
                        from tablename
                        order by (field1||'-top')

ie. order the records by the contents of field1 with the text "-top"
concatenated to it.  It doesn't work, I get a parse error.

Can anyone offer advice?

Thanks.

- --
JEREMY MALCOLM Jeremy@Malcolm.wattle.id.au http://malcolm.wattle.id.au
SIG of the day: [ ] Contact  [ ] Web  [ ] PGP  [ ] Taglines #1  [x] #2
"I'm a lawyer." "Honest?" "No, the usual kind." | Linux, the choice of
a GNU generation. | Are you the brain specialist? | "Could anyone pass
the sodium chloride, please?" - Adric (5W) | The Nanites have lawyers?

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.0.2i

iQB1AwUBOI3a6L/mBljD2JABAQG3RQL8DxUkukKGm7jEa9rSgyFzXMcd5KJejRxU
abscA8SuVq7ENXdFncx+5OsAk0VQfzBkUkRlobD9LEFXm6aTsK2zqmlhdVsJFKyh
f/YOixdaGiNzE+9xfIpEz+iizzKBwPRy
=bED8
-----END PGP SIGNATURE-----

************

RE: [GENERAL] Can || be used in ORDER BY?

From
"Jeremy Malcolm"
Date:
-----BEGIN PGP SIGNED MESSAGE-----

Hmm well it definitely doesn't work for me, so I guess I need to
upgrade from version 6.3.2 in order for it to work (unless there's
some other workaround).  Thanks...

- --
JEREMY MALCOLM Jeremy@Malcolm.wattle.id.au http://malcolm.wattle.id.au
SIG of the day: [x] Contact  [ ] Web  [ ] PGP  [ ] Taglines #1  [ ] #2
Residence: 208/112 Mounts Bay Road, West Perth, Western Australia 6005
Phone: +61-8-9226 0689 (H), +61-8-9325 4400 (W) | Fax: +61-8-9421 1762
Mobile: 0419 911 079 | Email: jmm@proctors.com.au, info@netcafe.net.au


-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.0.2i

iQB1AwUBOI6Hmr/mBljD2JABAQFnTgMArXpc2rom84IwGdtNVs4K/yeGTbhOjRjp
JC20qoZnAnkusR8BSfrZ7cUSJGnEKvAfyI7hQDXxLVXFsWuSgRhsdnJgtLjKMcJV
xXrsg+nK5hBw0opkFXjpX2Fl2XtLiknD
=6/MF
-----END PGP SIGNATURE-----