我想在PostgreSQL数据库内部创建一个简单的表。从我有的文档中CREATE TABLE will create a new, initially empty table in the current database. The table will be owned by the user issuing the command.
使用此命令
CREATE TABLE *table_name*;
我以为我得到了一个新的空表ERROR: syntax error at or near ";"
。但是psql抛出了。当我使用一个空的参数列表时,例如:
CREATE TABLE *table_name*();
psql告诉我该表是通过以下方式创建的
postgres=# create table *table_name*();
CREATE TABLE
但是\ l显示未显示新创建的表。而且也无法使用psql -d table_name -U user_name登录。有人可以帮忙吗?
您可以有一个没有列,甚至有一些行的表:
CREATE TABLE nocolumn (dummy INTEGER NOT NULL PRIMARY KEY)
;
INSERT INTO nocolumn(dummy) VALUES (1);
ALTER TABLE nocolumn
DROP COLUMN dummy;
\d nocolumn
SELECT COUNT(*) FROM nocolumn;
输出:
CREATE TABLE
INSERT 0 1
ALTER TABLE
Table "tmp.nocolumn"
Column | Type | Modifiers
--------+------+-----------
count
-------
1
(1 row)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句