Thread: column order
hi, all. i have a couple of questions regarding the order of table columns. say, you have a following query; SELECT id, firstname, lastname, dob FROM student; does postgresql guarantee you that the columns in the result set would be ordered as specified in the query (i.e. id, firstname, lastname, dob) ?
On May 24, 2006, at 11:54 , nuno wrote: > does postgresql guarantee you that > the columns in the result set would be ordered > as specified in the query (i.e. id, firstname, lastname, dob) ? No. If you want a specific order, use the ORDER BY clause. Michael Glaesemann grzm seespotcode net
am 24.05.2006, um 21:54:25 +0900 mailte Michael Glaesemann folgendes: > > On May 24, 2006, at 11:54 , nuno wrote: > > >does postgresql guarantee you that > >the columns in the result set would be ordered > >as specified in the query (i.e. id, firstname, lastname, dob) ? > > No. If you want a specific order, use the ORDER BY clause. Moment. If he say: 'select col1, col2, col3 ...', then in the result the column-order ist col1, col2, col3. If he want to sort the rows on col1, then he need the ORDER BY. HTH, Andreas -- Andreas Kretschmer (Kontakt: siehe Header) Heynitz: 035242/47215, D1: 0160/7141639 GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net === Schollglas Unternehmensgruppe ===
Michael Glaesemann wrote: > > On May 24, 2006, at 11:54 , nuno wrote: > >> does postgresql guarantee you that >> the columns in the result set would be ordered >> as specified in the query (i.e. id, firstname, lastname, dob) ? > > No. If you want a specific order, use the ORDER BY clause. I think the OP was talking about the order by the _columns_, not the _rows_. Postgres guarantees that order - Anything else would be simply insane. greetings, Florian Pflug
On May 24, 2006, at 22:36 , Florian G. Pflug wrote: > Michael Glaesemann wrote: >> On May 24, 2006, at 11:54 , nuno wrote: >>> does postgresql guarantee you that >>> the columns in the result set would be ordered >>> as specified in the query (i.e. id, firstname, lastname, dob) ? >> No. If you want a specific order, use the ORDER BY clause. > I think the OP was talking about the order by the _columns_, not > the _rows_. > > Postgres guarantees that order - Anything else would be simply insane. Wow. I didn't even consider that's what was being asked. (Does that make me sane?) I had assumed he mean the rows would be ordered in the order of the columns. For example, select foo, bar, baz from blurfl would be (by default) equivalent to select foo, bar, baz from blurfl order by foo, bar, baz. Thanks, Florian (and Andreas) for the sanity check. (Still haven't heard back from the OP though.) Michael Glaesemann grzm seespotcode net
hi, all. thanks for the replies. yes, i meant 'columns' not 'rows'. sorry if i made you a bit confused. my explanation should've been more descriptive than that i suppose. anyway, it's good to know that postgresql guarantees the column order. i was just trying to be double-safe before i mess up with the data. thanks.