pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
ORDER BY TABLENAME, possible bug
6+ messages / 6 participants
[nested] [flat]

* ORDER BY TABLENAME, possible bug
@ 2016-10-29 12:13  dv <udv.mail@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

From: dv @ 2016-10-29 12:13 UTC (permalink / raw)
  To: pgsql-bugs

E.g. query:

SELECT col1, col2, col3
FROM table1
ORDER BY table1

Postgres uses col1 for ASC ordering, if we write "ORDER BY table1
DESC" then DESC-ordering. I'm not sure this is a bug, but didn't find
description for such behaviour.

Best regards, Dmitry.


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: ORDER BY TABLENAME, possible bug
@ 2016-10-29 14:23  Pavel Stehule <pavel.stehule@gmail.com>
  parent: dv <udv.mail@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Pavel Stehule @ 2016-10-29 14:23 UTC (permalink / raw)
  To: dv <udv.mail@gmail.com>; +Cc: pgsql-bugs

Hi

2016-10-29 14:13 GMT+02:00 dv <udv.mail@gmail.com>:

> E.g. query:
>
> SELECT col1, col2, col3
> FROM table1
> ORDER BY table1
>
> Postgres uses col1 for ASC ordering, if we write "ORDER BY table1
> DESC" then DESC-ordering. I'm not sure this is a bug, but didn't find
> description for such behaviour.
>

It is not bug. Postgresql's table has fictive column with same name as
tablename that is composite of all columns

postgres=# select * from foo;
┌────┬────┐
│ a  │ b  │
╞════╪════╡
│ 10 │ 20 │
└────┴────┘
(1 row)

Time: 0.837 ms
postgres=# select foo from foo;
┌─────────┐
│   foo   │
╞═════════╡
│ (10,20) │
└─────────┘
(1 row)

 Regards

Pavel


> Best regards, Dmitry.
>
>
> --
> Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs
>


^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: ORDER BY TABLENAME, possible bug
@ 2016-11-18 22:35  Pantelis Theodosiou <ypercube@gmail.com>
  parent: Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Pantelis Theodosiou @ 2016-11-18 22:35 UTC (permalink / raw)
  To: Pavel Stehule <pavel.stehule@gmail.com>; +Cc: dv <udv.mail@gmail.com>; pgsql-bugs

On Sat, Oct 29, 2016 at 3:23 PM, Pavel Stehule <pavel.stehule@gmail.com>
wrote:

> Hi
>
> 2016-10-29 14:13 GMT+02:00 dv <udv.mail@gmail.com>:
>
>> E.g. query:
>>
>> SELECT col1, col2, col3
>> FROM table1
>> ORDER BY table1
>>
>> Postgres uses col1 for ASC ordering, if we write "ORDER BY table1
>> DESC" then DESC-ordering. I'm not sure this is a bug, but didn't find
>> description for such behaviour.
>>
>
> It is not bug. Postgresql's table has fictive column with same name as
> tablename that is composite of all columns
>
>
>
Is this somewhere in the documentation?  The only place I could find where
there is a hint of this use, is the Note in Row Constructors in
https://www.postgresql.org/docs/current/static/sql-expressions.html that
uses a table alias without the .* in an expression:   ROW(t, 42)

Pantelis Theodosiou

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: ORDER BY TABLENAME, possible bug
@ 2016-11-18 22:48  David G. Johnston <david.g.johnston@gmail.com>
  parent: Pantelis Theodosiou <ypercube@gmail.com>
  0 siblings, 2 replies; 6+ messages in thread

From: David G. Johnston @ 2016-11-18 22:48 UTC (permalink / raw)
  To: Pantelis Theodosiou <ypercube@gmail.com>; +Cc: Pavel Stehule <pavel.stehule@gmail.com>; dv <udv.mail@gmail.com>; pgsql-bugs

On Fri, Nov 18, 2016 at 3:35 PM, Pantelis Theodosiou <ypercube@gmail.com>
wrote:

>
>
> On Sat, Oct 29, 2016 at 3:23 PM, Pavel Stehule <pavel.stehule@gmail.com>
> wrote:
>
>> Hi
>>
>> 2016-10-29 14:13 GMT+02:00 dv <udv.mail@gmail.com>:
>>
>>> E.g. query:
>>>
>>> SELECT col1, col2, col3
>>> FROM table1
>>> ORDER BY table1
>>>
>>> Postgres uses col1 for ASC ordering, if we write "ORDER BY table1
>>> DESC" then DESC-ordering. I'm not sure this is a bug, but didn't find
>>> description for such behaviour.
>>>
>>
>> It is not bug. Postgresql's table has fictive column with same name as
>> tablename that is composite of all columns
>>
>>
>>
> Is this somewhere in the documentation?  The only place I could find where
> there is a hint of this use, is the Note in Row Constructors in
> https://www.postgresql.org/docs/current/static/sql-expressions.html that
> uses a table alias without the .* in an expression:   ROW(t, 42)
>


​https://www.postgresql.org/docs/9.6/static/rowtypes.html

​"Whenever you create a table, a composite type is also automatically
created, with the same name as the table, to represent the table's row
type."

So, its documented and in technically correct location.  I'm not sure if
introducing this material in a "tutorial" would be a gain or just confuse
the student.  It seems to be something one picks up somehow (trial and
error, mailing list, stumbling upon it in the docs or elsewhere on the
Internet) as one increases their knowledge of SQL to an intermediate level.

David J.

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: ORDER BY TABLENAME, possible bug
@ 2016-11-18 23:33  Tom Lane <tgl@sss.pgh.pa.us>
  parent: David G. Johnston <david.g.johnston@gmail.com>
  1 sibling, 0 replies; 6+ messages in thread

From: Tom Lane @ 2016-11-18 23:33 UTC (permalink / raw)
  To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: Pantelis Theodosiou <ypercube@gmail.com>; Pavel Stehule <pavel.stehule@gmail.com>; dv <udv.mail@gmail.com>; pgsql-bugs

"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Fri, Nov 18, 2016 at 3:35 PM, Pantelis Theodosiou <ypercube@gmail.com>
> wrote:
>> Is this somewhere in the documentation?

> ​https://www.postgresql.org/docs/9.6/static/rowtypes.html
> ​"Whenever you create a table, a composite type is also automatically
> created, with the same name as the table, to represent the table's row
> type."

> So, its documented and in technically correct location.  I'm not sure if
> introducing this material in a "tutorial" would be a gain or just confuse
> the student.  It seems to be something one picks up somehow (trial and
> error, mailing list, stumbling upon it in the docs or elsewhere on the
> Internet) as one increases their knowledge of SQL to an intermediate level.

There's a whole bunch of behaviors around composite values that are
documented in scattered places, some of which are completely not where
you'd expect to look.  In this example, the fact that you can use a table
name/alias to represent the composite value of the current row is
something that isn't exactly obvious, much less how that relates to other
possible spellings such as "TABLENAME.*".  We had a related question just
a couple weeks ago, which caused me to wonder (not for the first time)
whether we could pull together some sort of unified presentation.
I haven't done anything about it though.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: ORDER BY TABLENAME, possible bug
@ 2016-11-18 23:37  Thomas Kellerer <spam_eater@gmx.net>
  parent: David G. Johnston <david.g.johnston@gmail.com>
  1 sibling, 0 replies; 6+ messages in thread

From: Thomas Kellerer @ 2016-11-18 23:37 UTC (permalink / raw)
  To: pgsql-bugs

David G. Johnston schrieb am 18.11.2016 um 23:48:
>
> Is this somewhere in the documentation? The only place I could find
> where there is a hint of this use, is the Note in Row Constructors in
> https://www.postgresql.org/docs/current/static/sql-expressions.html
> <https://www.postgresql.org/docs/current/static/sql-expressions.html;
> that uses a table alias without the .* in an expression: ROW(t, 42)
>
> ​https://www.postgresql.org/docs/9.6/static/rowtypes.html
>
> ​"Whenever you create a table, a composite type is also automatically created, with the same name as the table, to represent the table's row type."
>
> So, its documented and in technically correct location. I'm not sure
> if introducing this material in a "tutorial" would be a gain or just
> confuse the student. It seems to be something one picks up somehow
> (trial and error, mailing list, stumbling upon it in the docs or
> elsewhere on the Internet) as one increases their knowledge of SQL to
> an intermediate level.

I think the chapter about "Select Lists"[1] would be the approriate place to explain this.

I would also love to see an explanation there on why "select (a,b,c)" is something different then "select a,b,c"

I see far too many people putting the columns of the select list between parentheses and then being confused about the output.

I don't know if the Postgres behaviour is mandated by the SQL standard.

If it's not, that should be documented, maybe in the chapter I mentioned above or in the compatibility section of SELECT.
If that _is_ mandated by the standard, then I think some small note/warning might be useful (especially to newcomers)

Thomas



[1] https://www.postgresql.org/docs/current/static/queries-select-lists.html



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2016-11-18 23:37 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-10-29 12:13 ORDER BY TABLENAME, possible bug dv <udv.mail@gmail.com>
2016-10-29 14:23 ` Pavel Stehule <pavel.stehule@gmail.com>
2016-11-18 22:35   ` Pantelis Theodosiou <ypercube@gmail.com>
2016-11-18 22:48     ` David G. Johnston <david.g.johnston@gmail.com>
2016-11-18 23:33       ` Tom Lane <tgl@sss.pgh.pa.us>
2016-11-18 23:37       ` Thomas Kellerer <spam_eater@gmx.net>

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