PostgreSQL column 'foo' does not exist

前端 未结 10 2105
盖世英雄少女心
盖世英雄少女心 2020-12-05 12:32

I have a table that has 20 integer columns and 1 text column named \'foo\'

If I run query:

SELECT * from table_name where foo is NULL
相关标签:
10条回答
  • 2020-12-05 13:23

    If for some reason you have created a mixed-case or upper-case column name, you need to quote it, or get this error:

    test=> create table moo("FOO" int);
    CREATE TABLE
    test=> select * from moo;
     FOO 
    -----
    (0 rows)
    test=> select "foo" from moo;
    ERROR:  column "foo" does not exist
    LINE 1: select "foo" from moo;
                   ^
    test=> _
    

    Note how the error message gives the case in quotes.

    0 讨论(0)
  • 2020-12-05 13:27

    I fixed similar issues by qutating column name

    SELECT * from table_name where "foo" is NULL;
    

    In my case it was just

    SELECT id, "foo" from table_name;
    

    without quotes i'v got same error.

    0 讨论(0)
  • 2020-12-05 13:30

    PostreSQL apparently converts column names to lower case in a sql query - I've seen issues where mixed case column names will give that error. You can fix it by putting the column name in quotation marks:

    SELECT * FROM table_name where "Foo" IS NULL
    
    0 讨论(0)
  • 2020-12-05 13:35

    I fixed it by changing the quotation mark (") with apostrophe (') inside Values. For instance:

    insert into trucks ("id","datetime") VALUES (862,"10-09-2002 09:15:59");

    Becomes this:

    insert into trucks ("id","datetime") VALUES (862,'10-09-2002 09:15:59');

    Assuming datetime column is VarChar.

    0 讨论(0)
提交回复
热议问题