SQLite3 column truncation even though column is wide enough

I have a table with schema

CREATE TABLE test(id INTEGER NOT NULL PRIMARY KEY, numbers TEXT);

and values

INSERT INTO test(numbers) VALUES('1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100');

And if I run these commands

.mode box
.headers on
.width 0 400
.once -e
SELECT * FROM test;

I get output as

┌────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ id │                                                                                                                                                                                                     numbers                                                                                                                                                                                                      │
├────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ 1  │ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86 │
└────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

numbers column gets truncated even though the headers are not and the column is wide enough.
I tried increasing width value but still wouldn’t work

This happens with box, column, table and markdown modes only. Other modes work fine.

What am I doing wrong?

I am using SQLite version 3.33.0 2020-08-14 13:23:32

Go to Source
Author: just_chilling

How to query/join tables where foreign key constraint is set in schema

I’m relatively new to sqlite and databases in general.
I’ve successfully setup a schema of 4 tables, each having a foreign key pointing to its parent table. The schema also has the foreign key constraint set on the child keys.

Performing a query where every table is joined with the SELECT * FROM…JOIN…ON ……… works without issue, but it is laborious manually connecting the keys.

My question is: Is it possible to perform a query/join of the tables without the ON statement which links each parent/child key relationship? Since this was already established in the schema definition, this seems to be redundant. I’m trying to simplify the sql command and make use of the parent/child relationship already defined. When I perform said query but omit the ON statements, the results are not what I expected. Any guidance is appreciated.

Go to Source
Author: Bill Fujimoto

Getting proper output of my SELECT clause. SQLite

I am coding a bus connection search engine. My goal is to see the time when the bus is departing, while the stop_from and stop_to names are provided.

I have created the STOP table

CREATE TABLE STOP (
ID INTEGER PRIMARY KEY,
STOP_NAME TEXT NOT NULL,
ROUTE_ID INTEGER NOT NULL
);

and the TIMETABLE table

CREATE TABLE TIMETABLE (
ID INTEGER PRIMARY KEY, 
TIME TEXT NOT NULL,
STOP_ID INTEGER NOT NULL,
FOREIGN KEY (STOP_ID) REFERENCES STOP (ID)
);

The route starts in Lidzbark Warmiński and leads via Smolajny and Dobre Miasto to Olsztyn. There are four connections per day. And I have also inserted all the possible routes from Lidzbark Warmiński to Olsztyn

INSERT INTO STOP VALUES
(1,'Lidzbark Warmiński', 1),
(2, 'Smolajny', 1),
(3, 'Dobre Miasto', 1),
(4, 'Olsztyn', 1),
(5, 'Lidzbark Warmiński', 2),
(6, 'Smolajny', 2),
(7, 'Dobre Miasto', 2),
(8, 'Lidzbark Warmiński', 3),
(9, 'Smolajny', 3),
(10, 'Smolajny', 4),
(11, 'Dobre Miasto', 4),
(12, 'Smolajny', 5),
(13, 'Olsztyn', 5),
(14, 'Dobre Miasto', 6),
(15, 'Olsztyn', 6),
(16, 'Smolajny', 7),
(17, 'Dobre Miasto', 7),
(18, 'Olsztyn', 7);

and the timetables regarding them

INSERT INTO TIMETABLE VALUES
--towards Olsztyn
(1, '08:00', 1),
(2, '12:00', 1),
(3, '15:00', 1),
(4, '19:00', 1),
(5, '08:00', 2),
(6, '12:00', 2),
(7, '15:00', 2),
(8, '19:00', 2),
(9, '08:00', 3),
(10, '12:00', 3),
(11, '15:00', 3),
(12, '19:00', 3),
(13, '08:20', 4),
(14, '12:20', 4),
(15, '15:20', 4),
(16, '19:20', 4),
(17, '08:20', 5),
(18, '12:20', 5),
(19, '15:20', 5),
(20, '19:20', 5),
(21, '08:30', 6),
(22, '12:30', 6),
(23, '15:30', 6),
(24, '19:30', 6),
(25, '08:20', 7),
(26, '12:20', 7),
(27, '15:20', 7),
(28, '19:20', 7);

I am developing under python 3.8 and this is a function with my SELECT clause

def fetch_hours(cursor, stop_from_name, stop_to_name):
    cursor.execute(
        '''SELECT T.TIME FROM TIMETABLE T
             JOIN STOP S1 ON T.STOP_ID = S1.ID 
             JOIN STOP S2 ON S2.ROUTE_ID = S1.ROUTE_ID 
             WHERE S1.STOP_NAME = ? 
             AND S2.STOP_NAME = ? ORDER BY T.TIME ASC''', 
        (stop_from_name, stop_to_name)) 
    return cursor.fetchall()

However, I have encountered some problems. For a wide range of bus stops this code doesn’t work well. Providing stop_from Smolajny and stop_to Dobre Miasto, the result is

Departures: 08:00, 08:30, 12:00, 12:30, 15:00, 15:30, 19:00, 19:30

While I would like to see only four hours. For some connections it doesn’t work at all and for some it is OK.

The desired effect is to see four departure hours for any stop_from and stop_to on this route (from Lidzbark Warmiński to Olsztyn). The reverse route is now commented, and if it would be helpful, the rest of my code can be achieved here: https://github.com/wwmarkositrawe/autobusy-backend

While looking for help,
Wishing you best regards,
marasecki

Go to Source
Author: marasecki