Issue
I used double quotes on "NAME" to make it case sensitive but it still doesn't work. I get an error saying that the column "name" doesn't exist.
(i use jupyter notebook and sql magic commands)
ppg = [[],[]]
for x in overall_ppg_leaders:
reg_ppg = %sql SELECT * FROM "rg_player_stats" WHERE "NAME" = :x;
po_ppg = %sql SELECT * FROM "po_player_stats" WHERE "NAME" = :x;
ppg[0].append(reg_ppg)
ppg[1].append(po_ppg)
print(ppg)
I get error:
* postgresql+psycopg2://postgres:***@localhost/NBA_2021-22
(psycopg2.errors.UndefinedColumn) column "name" does not exist
LINE 1: SELECT * FROM rg_player_stats WHERE NAME = 'Kevin Durant';
^
[SQL: SELECT * FROM rg_player_stats WHERE NAME = %(x)s;]
[parameters: {'x': 'Kevin Durant'}]
(Background on this error at: https://sqlalche.me/e/14/f405)
* postgresql+psycopg2://postgres:***@localhost/NBA_2021-22
(psycopg2.errors.UndefinedColumn) column "name" does not exist
LINE 1: SELECT * FROM po_player_stats WHERE NAME = 'Kevin Durant';
^
[SQL: SELECT * FROM po_player_stats WHERE NAME = %(x)s;]
[parameters: {'x': 'Kevin Durant'}]
(Background on this error at: https://sqlalche.me/e/14/f405)
* postgresql+psycopg2://postgres:***@localhost/NBA_2021-22
(psycopg2.errors.UndefinedColumn) column "name" does not exist
LINE 1: SELECT * FROM rg_player_stats WHERE NAME = 'Donovan Mitchell...
^
I also noticed that column name with double quotes works when I use cell magic %%sql
but gives me an error when I use the single line magic %sql
Solution
When using single line magic command %sql
,
use "\"NAME\""
instead of "NAME" so that it is case sensitive.
ppg = [[],[]]
for x in overall_ppg_leaders:
reg_ppg = %sql SELECT "\"PPG\"" FROM "rg_player_stats" WHERE "\"NAME\"" = :x;
po_ppg = %sql SELECT "\"PPG\"" FROM "po_player_stats" WHERE "\"NAME\"" = :x;
ppg[0].append(reg_ppg)
ppg[1].append(po_ppg)
print(ppg)
This code WORKS
Answered By - RKS2
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.