Click here to Skip to main content
15,867,834 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL Query:

<pre lang="SQL">SELECT tod FROM Flights WHERE flno = 1;


The file from which I am inserting by the SQL Query is a separate *.ipynb jupyter notebook file and the file in which I created the table is a separate *.ipynb jupyter notebook file but both in the same folder. When I run the flights table its displaying the entries its only I have 5 entries and its displaying 25 entries. All the entries get repeated 5 times.

Aircraft table has a foreign key from Flights table which is "tod" thats why Aircraft table is creating problems in displaying the result instead of the sql query. How to correct this?

Error:

File "<ipython-input-40-7191c59c7b77>", line 55
entrya_1 = (1,'Air bus 1', (SELECT tod FROM Flights WHERE flno = 1;), '250 km')
^

SyntaxError: invalid syntax


The ^ sign is beneath 'd' of 'tod'


What I have tried:

Tried to run the SQL query in the same file where the table is created but the compiler giving the same error the rest I am not able to figure out.
Posted
Updated 12-Jun-20 14:31pm
Comments
CHill60 12-Jun-20 12:04pm    
Sorry this is not clear to me at all. What is the schema of the Flights table?
A. B. Dinshaa 12-Jun-20 13:29pm    
Flights(fino: integer, from: string, to: string, distance: integer, departs: time, arrives: time, price: integer)


Aircraft(aid: integer, aname: string, cruisingrange: integer)
MadMyche 12-Jun-20 13:53pm    
How about the primary keys and foreign keys?
A. B. Dinshaa 12-Jun-20 14:37pm    
Primary key are the first column of the table by default if they are not declared thats why I have not defined any primary key. You want to see the create table statement?
Foreign key I have declared in one table.
There is one table that contains only composite keys but right now I am stuck in foreign keys table.
MadMyche 12-Jun-20 16:28pm    
Without having all the details of the schema that is involved, it is really hard to try and help you. Probably does not help that I am not jupyter adept, but looking at this from an SQL point of view just does not add-up
Flights( fino:     integer -- PK
       , from:     string
       , to:       string
       , distance: integer
       , departs:  time
       , arrives:  time
       , price:    integer
)

Aircraft( aid:           integer -- PK
        , aname:         string
        , cruisingrange: integer
)

SELECT tod
FROM   Flights
WHERE  flno = 1

1 solution

Based on the table structure you provided
Flights( fino:     integer -- PK
       , from:     string
       , to:       string
       , distance: integer
       , departs:  time
       , arrives:  time
       , price:    integer
)
Aircraft( aid:           integer -- PK
        , aname:         string
        , cruisingrange: integer
)
The following is going to be an invalid statement; as there is no column named tod in the Flights table; and thus the syntax error.
SQL
SELECT tod FROM Flights WHERE fino = 1
--       ^ SyntaxError: invalid syntax
 
Share this answer
 
Comments
A. B. Dinshaa 13-Jun-20 3:01am    
In jupyter notebook when error comes by the compiler there is no line number given in the cell of the jupyter notebook to trace exactly where the error is.

How to trace in jupyter notebook on which line the error is?
A. B. Dinshaa 13-Jun-20 3:45am    
As 'to' is a keyword in sql I wrote 'tod' in which d means destination
A. B. Dinshaa 13-Jun-20 3:55am    
In my jupyter notebook program I have used SQLite database whose abc.db file’s saving is disabled because the file abc.db is not UTF-8 encoded. I followed the procedure written below to make it UTF-8 encoded which is making it UTF-8 encoded just once and that is only when the abc.db is new once the file is used one or two times it starts giving errors which I am discussing for long. Once saving is disabled it cannot be enabled even temporarily. How to make saving enabled once again and permanently?


1. Open cmd and change encoding (chcp 65001)
2. Run sqlite3.exe from current windows
3. Change encoding (PRAGMA encoding="UTF-8";)
4. Create correct UTF-8 script.


The database file is not getting permanently in UTF-8 format permanently.
A. B. Dinshaa 13-Jun-20 11:44am    
I want jupyter notebook to automatically detect the ‘marks.db’ file in the folder so that wherever I place the folder containing the program it keeps on working. How to do it?

Right now the jupyter notebook catches the database file by the line stated below:

database = r"C:\Users\DaBroths\Desktop\abc\marks.db"

In order to create the connection I have to write in a separate connection file:

create_new_connection(r"C:\Users\DaBroths\Desktop\abc\marks.db")

This I also want to replace so that where ever I place the folder on the computer the program keeps on working, no need to change this folder path every time.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900