D
D
Dmitry2021-05-27 16:54:57
PostgreSQL
Dmitry, 2021-05-27 16:54:57

Creating a sorted table?

Good afternoon!

First day in PostgreSQL

Please tell me how to create a table, immediately sorting by the id column.
The script below, how to finish it, what would be stored sorted?

create table calendar(id integer,dt date, datename text);
insert into calendar
values
​​('202001','20200101','Jan.20'),
('202002','20200201','Feb.20'),
('202003','20200301','Mar.20' ),
('202004','20200401','Apr.20'),
('202005','20200501','May.20'),
('202006','20200601','Jun.20'),
('202007','20200701','Jul.20'),
('202008','
('202012','20201201','Dec.20'),
('202101','20210101','Jan.21'),
('202102','20210201','Feb.21'),
(' 202103','20210301','Mar.21'),
('202104','20210401','Apr.21');

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Melkij, 2021-05-27
@melkij

Impossible.
Postgresql has only heap out of the box - an unsorted heap.
Note that there is no sort at all in SQL other than the one you explicitly requested in the query with ORDER BY.

V
Vladimir Korotenko, 2021-05-27
@firedragon

Well, that's how it will turn out. What is your problem? Besides the primary index?

V
Vasily Bannikov, 2021-05-27
@vabka

When doing a SELECT, always specify ORDER BY explicitly.
This applies not only to pg, but also to other subds.
If ORDER BY is not specified, then the base engine has the right to display in the order in which it is more convenient for it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question