pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedCROSS JOIN ordering
2+ messages / 2 participants
[nested] [flat]
* CROSS JOIN ordering
@ 2011-05-11 23:19 Grzegorz Szpetkowski <gszpetkowski@gmail.com>
2011-05-12 11:01 ` Re: CROSS JOIN ordering Richard Huxton <dev@archonet.com>
0 siblings, 1 reply; 2+ messages in thread
From: Grzegorz Szpetkowski @ 2011-05-11 23:19 UTC (permalink / raw)
To: pgsql-sql
I am curious what is proper ordering for cross joining and joining at
all for two tables. I look at the example at
http://www.postgresql.org/docs/9.0/static/queries-table-expressions.html
and there is:
SELECT * FROM t1 CROSS JOIN t2;
num | name | num | value
-----+------+-----+-------
1 | a | 1 | xxx
1 | a | 3 | yyy
1 | a | 5 | zzz
2 | b | 1 | xxx
2 | b | 3 | yyy
2 | b | 5 | zzz
3 | c | 1 | xxx
3 | c | 3 | yyy
3 | c | 5 | zzz
(9 rows)
I thought that this should be rather:
1 | a | 1 | xxx
2 | b | 1 | xxx
3 | c | 1 | xxx
1 | a | 3 | yyy
2 | b | 3 | yyy
2 | b | 3 | yyy
1 | a | 5 | zzz
2 | b | 5 | zzz
3 | c | 5 | zzz
DROP TABLE t1, t2;
CREATE TABLE t1 (num int, char name);
CREATE TABLE t2 (num int, value varchar(3));
INSERT INTO t1 VALUES (1, 'a'), (2, 'b'), (3, 'c');
INSERT INTO t2 VALUES (1, 'xxx'), (2, 'yyy'), (3, 'zzz');
SELECT * FROM t1 CROSS JOIN t2;
num | char | num | value
-----+------+-----+-------
1 | a | 1 | xxx
2 | b | 1 | xxx
3 | c | 1 | xxx
1 | a | 2 | yyy
2 | b | 2 | yyy
3 | c | 2 | yyy
1 | a | 3 | zzz
2 | b | 3 | zzz
3 | c | 3 | zzz
(9 rows)
or even (same data as in documentation):
DROP TABLE t1, t2;
CREATE TABLE t1 (num int, char name);
CREATE TABLE t2 (num int, value varchar(3));
INSERT INTO t1 VALUES (1, 'a'), (2, 'b'), (3, 'c');
INSERT INTO t2 VALUES (1, 'xxx'), (3, 'yyy'), (5, 'zzz');
SELECT * FROM t1 CROSS JOIN t2;
num | char | num | value
-----+------+-----+-------
1 | a | 1 | xxx
2 | b | 1 | xxx
3 | c | 1 | xxx
1 | a | 3 | yyy
2 | b | 3 | yyy
3 | c | 3 | yyy
1 | a | 5 | zzz
2 | b | 5 | zzz
3 | c | 5 | zzz
(9 rows)
Is there any "proper", standard ordering that I can assume for sure ?
Maybe PostgreSQL 8.4/9.0 versions have strict ordering and older
versions are using mixed ordering depends on something I don't know (I
am just guessing).
Thanks in advance.
Regards,
G. Sz.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: CROSS JOIN ordering
2011-05-11 23:19 CROSS JOIN ordering Grzegorz Szpetkowski <gszpetkowski@gmail.com>
@ 2011-05-12 11:01 ` Richard Huxton <dev@archonet.com>
0 siblings, 0 replies; 2+ messages in thread
From: Richard Huxton @ 2011-05-12 11:01 UTC (permalink / raw)
To: Grzegorz Szpetkowski <gszpetkowski@gmail.com>; +Cc: pgsql-sql
On 12/05/11 00:19, Grzegorz Szpetkowski wrote:
> Is there any "proper", standard ordering that I can assume for sure ?
> Maybe PostgreSQL 8.4/9.0 versions have strict ordering and older
> versions are using mixed ordering depends on something I don't know (I
> am just guessing).
Queries do not have any guaranteed order unless you add an ORDER BY
clause. None of them, no matter how simple.
--
Richard Huxton
Archonet Ltd
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2011-05-12 11:01 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-05-11 23:19 CROSS JOIN ordering Grzegorz Szpetkowski <gszpetkowski@gmail.com>
2011-05-12 11:01 ` Richard Huxton <dev@archonet.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox