postgresql Postgres报一个关系不存在,但是表存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20729625/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Postgres reports that a relation does not exist, but the table exists
提问by jhamm
I have an express
app that I am connecting to my Postgres
db. Here is my code:
我有一个express
应用程序连接到我的Postgres
数据库。这是我的代码:
var express = require('express');
var app = express();
var pg = require('pg').native;
var connectionString = process.env.DATABASE_URL || 'postgres://localhost:5432/isx';
var port = process.env.PORT || 3000;
var client;
app.use(express.bodyParser());
client = new pg.Client(connectionString);
client.connect();
app.get('/users', function(req, res) {
'use strict';
console.log('/users');
var query = client.query('SELECT * FROM users');
query.on('row', function(row, result) {
result.addRow(row);
});
query.on('end', function(result) {
console.log(result);
res.json(result);
});
});
I go to my local Postgres
and look at the isx
db and here are the tables available.
我去我的本地Postgres
查看isx
数据库,这里有可用的表。
List of relations
Schema | Name | Type | Owner
--------+----------+-------+----------
public | projects | table | postgres
public | users | table | postgres
(2 rows)
But when I try to hit the users
table I get this error Error: relation "users" does not exist
.
但是当我尝试敲users
桌子时,我收到了这个错误Error: relation "users" does not exist
。
The relation users
exists. I have checked and I am connected to the instance of Postgres
that I thought I was connected to. What else can I be missing?
关系users
存在。我已经检查并连接到Postgres
我认为连接到的实例。我还能缺少什么?
采纳答案by Denis de Bernardy
Check for potential permission problems, e.g. an incorrect search path, or incorrect permissions, or something to that order. You could run this query to show all available tables, for instance:
检查潜在的权限问题,例如不正确的搜索路径、不正确的权限或该顺序的某些内容。您可以运行此查询以显示所有可用表,例如:
select relname
from pg_class c
where pg_table_is_visible(c.oid)
and relkind = 'r'
and relname not like E'pg\_%';
It might also be worth looking into case-sensitivity related issues. For instance, perhaps the pg
library is adding double-quotes around lowercase identifiers, and you created tables with CamelCase, or something to that order.
可能还值得研究与区分大小写相关的问题。例如,也许pg
库在小写标识符周围添加了双引号,并且您使用 CamelCase 或按照该顺序创建了表格。
Then check the search_path
if relevant:
然后检查search_path
是否相关:
show search_path;
If the path is correct, then check permissions, for instance using:
如果路径正确,则检查权限,例如使用:
select usename, nspname || '.' || relname as relation,
case relkind when 'r' then 'TABLE' when 'v' then 'VIEW' end as relation_type,
priv
from pg_class join pg_namespace on pg_namespace.oid = pg_class.relnamespace,
pg_user,
(values('SELECT', 1),('INSERT', 2),('UPDATE', 3),('DELETE', 4)) privs(priv, privorder)
where relkind in ('r', 'v')
and has_table_privilege(pg_user.usesysid, pg_class.oid, priv)
and not (nspname ~ '^pg_' or nspname = 'information_schema')
order by 2, 1, 3, privorder;
Taken from: Find out if user got permission to select/update/... a table/function/... in PostgreSQL
摘自:找出用户是否有权在 PostgreSQL 中选择/更新/...一个表/函数/...
If relevant, fix the permissions using alter schema
and/or alter table
:
如果相关,请使用alter schema
和/或修复权限alter table
: