Cannot simply use PostgreSQL table name (“relation does not exist”)

后端 未结 11 2638
一向
一向 2020-11-22 05:35

I\'m trying to run the following PHP script to do a simple database query:

$db_host = \"localhost\";
$db_name = \"showfinder\";
$username = \"user\";
$passwo         


        
相关标签:
11条回答
  • 2020-11-22 05:53

    Easiest workaround is Just change the table name and all column names to lowercase and your issue will be resolved.

    For example:

    • Change Table_Name to table_name and
    • Change ColumnName to columnname
    0 讨论(0)
  • 2020-11-22 05:56

    You have to add the schema first e.g.

    SELECT * FROM place.user_place;
    

    If you don't want to add that in all queries then try this:

    SET search_path TO place;
    

    Now it will works:

    SELECT * FROM user_place;
    
    0 讨论(0)
  • 2020-11-22 05:58

    I had a similar problem on OSX but tried to play around with double and single quotes. For your case, you could try something like this

    $query = 'SELECT * FROM "sf_bands"'; // NOTE: double quotes on "sf_Bands"
    
    0 讨论(0)
  • 2020-11-22 06:02

    I had problems with this and this is the story (sad but true) :

    1. If your table name is all lower case like : accounts you can use: select * from AcCounTs and it will work fine

    2. If your table name is all lower case like : accounts The following will fail: select * from "AcCounTs"

    3. If your table name is mixed case like : Accounts The following will fail: select * from accounts

    4. If your table name is mixed case like : Accounts The following will work OK: select * from "Accounts"

    I dont like remembering useless stuff like this but you have to ;)

    0 讨论(0)
  • 2020-11-22 06:02

    If a table name contains underscores or upper case, you need to surround it in double-quotes.

    SELECT * from "Table_Name";
    
    0 讨论(0)
  • 2020-11-22 06:05

    Put the dbname parameter in your connection string. It works for me while everything else failed.

    Also when doing the select, specify the your_schema.your_table like this:

    select * from my_schema.your_table
    
    0 讨论(0)
提交回复
热议问题