pg数据库创建表因为表面前面有空格导致创建成功后无法使用该表

文章讨论了在数据库中遇到的错误,涉及到创建表(如`test`)时遇到的‘relationdoesnotexist’错误,以及表格名前的空格导致的访问问题。作者还展示了如何创建新表并管理已存在的同名表。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

def=# create table  test(c1 int,c2 text);
CREATE TABLE
def=# select count(*) from test;
ERROR:  relation "test" does not exist
LINE 1: select count(*) from test;
可以发现数据库报错找不到该表

查看表的详细信息
def=# \d+
                                    List of relations
 Schema | Name  | Type  |  Owner   | Persistence | Access method |  Size   | Description
--------+-------+-------+----------+-------------+---------------+---------+-------------
 public | a     | table | postgres | permanent   | heap          | 0 bytes |
 public |  test | table | postgres | permanent   | heap          | 501 MB  |
可以发现该表前面存在控格导致无法访问

而且数据库还能创建test表
def=# create table test (id int);
CREATE TABLE
def=# \d+
                                    List of relations
 Schema | Name  | Type  |  Owner   | Persistence | Access method |  Size   | Description
--------+-------+-------+----------+-------------+---------------+---------+-------------
 public | a     | table | postgres | permanent   | heap          | 0 bytes |
 public | test  | table | postgres | permanent   | heap          | 0 bytes |
 public |  test | table | postgres | permanent   | heap          | 501 MB  |
(3 rows)
需要对该表进行操作可以粘贴name来实现。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值