postgresql – Postgres报告关系不存在,但表存在
我有一个快速的应用程序,我正在连接到我的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); }); }); 我去我当地的Postgres看看isx db,这里有可用的表格. List of relations Schema | Name | Type | Owner --------+----------+-------+---------- public | projects | table | postgres public | users | table | postgres (2 rows) 但是,当我尝试点击用户表时,我收到此错误错误:关系“用户”不存在. 关系用户存在.我已经检查过,并且我已经连接到Postgres的实例,我认为我已连接到该实例.我还能错过什么? 解决方法
检查潜在的权限问题,例如不正确的搜索路径,或不正确的权限,或该订单的某些内容.您可以运行此查询以显示所有可用表,例如:
select relname from pg_class c where pg_table_is_visible(c.oid) and relkind = 'r' and relname not like E'pg_%'; 也可能值得研究区分大小写的相关问题.例如,也许pg库在小写标识符周围添加双引号,并且您使用CamelCase创建了表,或者该命令的某些内容. 然后检查search_path(如果相关): show search_path; 如果路径正确,则检查权限,例如使用: 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; 取自:Find out if user got permission to select/update/… a table/function/… in PostgreSQL 如果相关,请使用alter schema和/或alter table修复权限: > http://www.postgresql.org/docs/current/static/sql-alterschema.html (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |