使用psql运行CREATE TABLE之后,找不到该表

问题描述

我一直试图在Postgresql中创建一个表,但是当我尝试使用\dt-Did not find any relations.列出表时出现以下错误

我在名为create数据库中使用了以下create table jobs( id serial primary key,title text,link text,company text)语句-scrape

如果我使用\dt *.*,则会出现似乎是内置表的列表-

List of relations
       Schema       |          Name           | Type  |  Owner   
--------------------+-------------------------+-------+----------
 @R_483_4045@ion_schema | sql_features            | table | postgres
 @R_483_4045@ion_schema | sql_implementation_info | table | postgres
 @R_483_4045@ion_schema | sql_languages           | table | postgres
 @R_483_4045@ion_schema | sql_packages            | table | postgres
 @R_483_4045@ion_schema | sql_parts               | table | postgres
 @R_483_4045@ion_schema | sql_sizing              | table | postgres
 @R_483_4045@ion_schema | sql_sizing_profiles     | table | postgres
 pg_catalog         | pg_aggregate            | table | postgres
 pg_catalog         | pg_am                   | table | postgres
 pg_catalog         | pg_amop                 | table | postgres
 pg_catalog         | pg_amproc               | table | postgres
 pg_catalog         | pg_attrdef              | table | postgres
 pg_catalog         | pg_attribute            | table | postgres
 pg_catalog         | pg_auth_members         | table | postgres
 pg_catalog         | pg_authid               | table | postgres
 pg_catalog         | pg_cast                 | table | postgres
 pg_catalog         | pg_class                | table | postgres
 pg_catalog         | pg_collation            | table | postgres
 pg_catalog         | pg_constraint           | table | postgres
 pg_catalog         | pg_conversion           | table | postgres
 pg_catalog         | pg_database             | table | postgres
 pg_catalog         | pg_db_role_setting      | table | postgres
 pg_catalog         | pg_default_acl          | table | postgres
 pg_catalog         | pg_depend               | table | postgres
 pg_catalog         | pg_description          | table | postgres
 pg_catalog         | pg_enum                 | table | postgres
 pg_catalog         | pg_event_trigger        | table | postgres
 pg_catalog         | pg_extension            | table | postgres
 pg_catalog         | pg_foreign_data_wrapper | table | postgres
 pg_catalog         | pg_foreign_server       | table | postgres
 pg_catalog         | pg_foreign_table        | table | postgres
 pg_catalog         | pg_index                | table | postgres
 pg_catalog         | pg_inherits             | table | postgres
 pg_catalog         | pg_init_privs           | table | postgres
 pg_catalog         | pg_language             | table | postgres
 pg_catalog         | pg_largeobject          | table | postgres
 pg_catalog         | pg_largeobject_Metadata | table | postgres
 pg_catalog         | pg_namespace            | table | postgres
 pg_catalog         | pg_opclass              | table | postgres
 pg_catalog         | pg_operator             | table | postgres
 pg_catalog         | pg_opfamily             | table | postgres
 pg_catalog         | pg_partitioned_table    | table | postgres
 pg_catalog         | pg_pltemplate           | table | postgres
 pg_catalog         | pg_policy               | table | postgres
 pg_catalog         | pg_proc                 | table | postgres
 pg_catalog         | pg_publication          | table | postgres
 pg_catalog         | pg_publication_rel      | table | postgres
 pg_catalog         | pg_range                | table | postgres
 pg_catalog         | pg_replication_origin   | table | postgres
 pg_catalog         | pg_rewrite              | table | postgres
 pg_catalog         | pg_seclabel             | table | postgres
 pg_catalog         | pg_sequence             | table | postgres
 pg_catalog         | pg_shdepend             | table | postgres
 pg_catalog         | pg_shdescription        | table | postgres
 pg_catalog         | pg_shseclabel           | table | postgres
 pg_catalog         | pg_statistic            | table | postgres
 pg_catalog         | pg_statistic_ext        | table | postgres
 pg_catalog         | pg_statistic_ext_data   | table | postgres
 pg_catalog         | pg_subscription         | table | postgres
 pg_catalog         | pg_subscription_rel     | table | postgres
 pg_catalog         | pg_tablespace           | table | postgres
 pg_catalog         | pg_transform            | table | postgres
 pg_catalog         | pg_trigger              | table | postgres
 pg_catalog         | pg_ts_config            | table | postgres
 pg_catalog         | pg_ts_config_map        | table | postgres
 pg_catalog         | pg_ts_dict              | table | postgres
 pg_catalog         | pg_ts_parser            | table | postgres
 pg_catalog         | pg_ts_template          | table | postgres
 pg_catalog         | pg_type                 | table | postgres
 pg_catalog         | pg_user_mapping         | table | postgres

我还检查了模式是否公开-

                          List of schemas
  Name  |  Owner   |  Access privileges   |      Description       
--------+----------+----------------------+------------------------
 public | postgres | postgres=UC/postgres+| standard public schema
        |          | =UC/postgres         | 
(1 row)


如果有帮助,我也在此处包括用户-

 Role name |                         Attributes                         | Member of 
-----------+------------------------------------------------------------+-----------
 arif      | Superuser,Create role,Create DB                          | {}
 postgres  | Superuser,Create DB,Replication,Bypass RLS | {}

我还检查了数据库-

scrape-# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 arif      | arif     | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 scrape    | arif     | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(5 rows)

解决方法

您对psql中的分号感到困惑。在一开始的每个人都会发生这种情况。

仅当psql收到终止该语句的分号时,该语句才发送到服务器。否则,您得到的只是提示稍有变化的提示,指示psql正在等待续行。

因此,如果您输入

CREATE TABLE mytab (x integer)

没有分号,什么都没发生。

然后您意识到忘记了分号,然后输入

CREATE TABLE mytab (x integer);

现在psql会将这两行视为一条语句并将其发送到服务器,这将导致您看到错误消息。

如有疑问,可以随时按 Ctrl + C 清除状态并丢弃语句缓冲区。