Postgresql tables exists, but getting “relation does not exist” when querying

后端 未结 8 2196
没有蜡笔的小新
没有蜡笔的小新 2020-11-30 23:22

I have a postgresql db with a number of tables. If I query:

SELECT column_name
FROM information_schema.columns
WHERE table_name=\"my_table\";
相关标签:
8条回答
  • 2020-11-30 23:59

    I was using pgAdmin to create my tables and while I was not using reserved words, the generated table had a quote in the name and a couple of columns had quotes in them. Here is an example of the generated SQL.

    CREATE TABLE public."Test"
    (
        id serial NOT NULL,
        data text NOT NULL,
        updater character varying(50) NOT NULL,
        "updateDt" time with time zone NOT NULL,
        CONSTRAINT test_pk PRIMARY KEY (id)
    )
    
    TABLESPACE pg_default;
    
    ALTER TABLE public."Test"
        OWNER to svc_newnews_app;
    

    All of these quotes were inserted at "random". I just needed to drop and re-create the table again without the quotes.

    Tested on pgAdmin 4.26

    0 讨论(0)
  • 2020-12-01 00:00

    You have to include the schema if isnt a public one

    SELECT *
    FROM <schema>."my_table"
    

    Or you can change your default schema

    SHOW search_path;
    SET search_path TO my_schema;
    

    Check your table schema here

    SELECT *
    FROM information_schema.columns
    

    For example if a table is on the default schema public both this will works ok

    SELECT * FROM parroquias_region
    SELECT * FROM public.parroquias_region
    

    But sectors need specify the schema

    SELECT * FROM map_update.sectores_point
    
    0 讨论(0)
提交回复
热议问题