简体   繁体   中英

(psycopg2.errors.UndefinedColumn) column "name" does not exist

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...
                                            ^

sql表

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

This code works fine在此处输入图像描述

This code gives me an error在此处输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM