select where expr in - result order?

Started by Andy Krigerover 23 years ago3 messagesgeneral
Jump to latest
#1Andy Kriger
akriger@greaterthanone.com

Is there any way to guarantee that the when using
SELECT * FROM tbl WHERE expr IN (scalar[,...])
the results are returned in the same order as the scalar list?

I realize I can do this by sorting the scalar list and using ORDER BY expr,
but I'd like to not count on a sorted list of scalars if at all possible.

thx
andy

#2Doug McNaught
doug@mcnaught.org
In reply to: Andy Kriger (#1)
Re: select where expr in - result order?

"Andy Kriger" <akriger@greaterthanone.com> writes:

Is there any way to guarantee that the when using
SELECT * FROM tbl WHERE expr IN (scalar[,...])
the results are returned in the same order as the scalar list?

I realize I can do this by sorting the scalar list and using ORDER BY expr,
but I'd like to not count on a sorted list of scalars if at all possible.

Nope, I'm pretty sure ORDER BY is the only way to do this. SQL
queries don't in general guarantee any ordering unless an ORDER BY
clause is used.

-Doug

#3Brian Minton
bminton@efn.org
In reply to: Doug McNaught (#2)
Re: select where expr in - result order?

Doug McNaught wrote:

Show quoted text

"Andy Kriger" <akriger@greaterthanone.com> writes:

Is there any way to guarantee that the when using
SELECT * FROM tbl WHERE expr IN (scalar[,...])
the results are returned in the same order as the scalar list?

I realize I can do this by sorting the scalar list and using ORDER BY expr,
but I'd like to not count on a sorted list of scalars if at all possible.

Nope, I'm pretty sure ORDER BY is the only way to do this. SQL
queries don't in general guarantee any ordering unless an ORDER BY
clause is used.

-Doug

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly