Postgresql表存在,但获取“关系不存在".查询时 [英] Postgresql tables exists, but getting "relation does not exist" when querying

查看:1057
本文介绍了Postgresql表存在,但获取“关系不存在".查询时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有许多表的postgresql数据库.如果我查询:

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";

我将获得正确返回的列的列表.

I will get a list of the columns returned properly.

但是,当我查询时:

SELECT *
FROM "my_table";

我得到了错误:

(ProgrammingError) relation "my_table" does not exist
'SELECT *\n    FROM "my_table"\n' {}

关于为什么我可以获取列但无法查询表的任何想法?目标是能够查询表.

Any thoughts on why I can get the columns, but can't query the table? Goal is to be able to query the table.

推荐答案

如果不是公共模式,则必须包括该模式

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;

在此处检查您的表架构

SELECT *
FROM information_schema.columns

例如,如果表位于默认架构public上,则两者都可以正常工作

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

但是部门需要指定架构

SELECT * FROM map_update.sectores_point

这篇关于Postgresql表存在,但获取“关系不存在".查询时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆