Organize by received_at device events into PostgreSQL database

Hello guys!!! I enabled the integration in the application server to save the events in a database in aws. I saved the events correctly but verified that they are not saved in order by received_at.

Follow the recommended structure:

create table device_up (
	id uuid primary key,
	received_at timestamp with time zone not null,
	dev_eui bytea not null,
	device_name varchar(100) not null,
	application_id bigint not null,
	application_name varchar(100) not null,
	frequency bigint not null,
	dr smallint not null,
	adr boolean not null,
	f_cnt bigint not null,
	f_port smallint not null,
	data bytea not null,
	rx_info jsonb not null,
	object jsonb not null
);

-- NOTE: These are recommended indices, depending on how this table is being
-- used, you might want to change these.
create index idx_device_up_received_at on device_up(received_at);
create index idx_device_up_dev_eui on device_up(dev_eui);
create index idx_device_up_application_id on device_up(application_id);
create index idx_device_up_frequency on device_up(frequency);
create index idx_device_up_dr on device_up(dr);

Is there any way to save the data in an organized way by received_at without 
having to use the postgres command "SELECT * FROM device_up ORDER BY received_at ASC" ?

If you want a consistent order without needing to add an order by clause, create a view.

1 Like

Rows are not returned in a specified order unless… well, specified.

The view option is a decent one, too.

1 Like