PostgreSQL column 'foo' does not exist

前端 未结 10 2140
盖世英雄少女心
盖世英雄少女心 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

    You accidentally created the column name with a trailing space and presumably phpPGadmin created the column name with double quotes around it:

    create table your_table (
        "foo " -- ...
    )
    

    That would give you a column that looked like it was called foo everywhere but you'd have to double quote it and include the space whenever you use it:

    select ... from your_table where "foo " is not null
    

    The best practice is to use lower case unquoted column names with PostgreSQL. There should be a setting in phpPGadmin somewhere that will tell it to not quote identifiers (such as table and column names) but alas, I don't use phpPGadmin so I don't where that setting is (or even if it exists).

提交回复
热议问题