postgresql 创建表
时间:2010-12-14
来源:互联网
现在刚学postgresql,
[root@v1 tool]# su - postgres
-bash-3.2$ -bash-3.2$
-bash-3.2$ psql -l
资料库列表
名称 | 拥有者 | 字元编码 | 排序规则 | Ctype | 存取权限
-----------+----------+----------+----------+-------+-----------------------
mydb | postgres | UTF8 | C | C | -----------》可以看见已经创建好的mydb数据库
postgres | postgres | UTF8 | C | C |
template0 | postgres | UTF8 | C | C | =c/postgres
: postgres=CTc/postgres
template1 | postgres | UTF8 | C | C | =c/postgres
: postgres=CTc/postgres
test | postgres | UTF8 | C | C |
(5 行记录)
下面我打算在数据库里,创建weather表,在表里添加己行数据
-bash-3.2$ psql mydb
psql (8.4.4)
输入 "help" 来获取帮助信息.
mydb=# COPY weather from '/tool/weather.txt'
mydb-# INSERT INTO weather VALUES ('San Francisco', 46, 50, 0.25, '1994-11-27')
mydb-# SELECT * FROM weather ---------------》没有任何显示和报错,不知道哪里问题 ?
[root@v1 tool]# cat /tool/weather.txt
city varchar(80),
temp_lo int, -- 最低气温
temp_hi int, -- 最高气温
prcp real, -- 降水量
date date
作者: dwm123 发布时间: 2010-12-14
mydb=# COPY weather from '/tool/weather.txt' ;
注意命令结尾加分号;

作者: tanfeng3 发布时间: 2010-12-14
mydb=# COPY weather from '/tool/weather.txt' ;
注意命令结尾加分号;

作者: tanfeng3 发布时间: 2010-12-14
作者: dwm123 发布时间: 2010-12-14
mydb=# COPY weather from '/tool/weather.txt';
ERROR: relation "weather" does not exist
作者: dwm123 发布时间: 2010-12-14
mydb=# COPY weather from '/tool/weather.txt';
ERROR: relation "weather" does no ...
dwm123 发表于 2010-12-14 10:42
weather 表建在哪个schema下? 加下前辍例如;
copy public.weather from '/tool/weather.txt';
作者: tanfeng3 发布时间: 2010-12-14
作者: tanfeng3 发布时间: 2010-12-14
回复 tanfeng3
我还是不太明白你的意思,我现在已经建立了一个数据库叫mydb, 现在只是想在mydb下面创建个weather的表,而且我现在已经在mydb的数据库里了。
mydb=# COPY mydb.weather from '/tool/weahter.txt' 如果不加分号,就不会报错,但是selcet * from weather 什么都不显示。
你说的加个前缀,我不是很明白,
mydb=# COPY mydb.weather from '/tool/weahter.txt'
ERROR: schema "mydb" does not exist
-bash-3.2$ psql -l
资料库列表
名称 | 拥有者 | 字元编码 | 排序规则 | Ctype | 存取权限
-----------+----------+----------+----------+-------+-----------------------
cities | postgres | UTF8 | C | C |
mydb | postgres | UTF8 | C | C |
postgres | postgres | UTF8 | C | C |
template0 | postgres | UTF8 | C | C | =c/postgres
: postgres=CTc/postgres
template1 | postgres | UTF8 | C | C | =c/postgres
: postgres=CTc/postgres
test | postgres | UTF8 | C | C |
(6 行记录)
我现在情况就这些,你能否直接点告诉我,在mydb里建立个weather 表,如何操作。
作者: dwm123 发布时间: 2010-12-14
作者: renxiao2003 发布时间: 2010-12-14
-bash-3.2$ createdb abc ---我这里加不加分号,都可以创建成功,我现在是想在mydb下面创建个表weather,
-bash-3.2$ pgsql -l
资料库列表
名称 | 拥有者 | 字元编码 | 排序规则 | Ctype | 存取权限
-----------+----------+----------+----------+-------+-----------------------
abc | postgres | UTF8 | C | C | ----------------------》刚创建
cities | postgres | UTF8 | C | C |
mydb | postgres | UTF8 | C | C |
postgres | postgres | UTF8 | C | C |
template0 | postgres | UTF8 | C | C | =c/postgres
: postgres=CTc/postgres
template1 | postgres | UTF8 | C | C | =c/postgres
: postgres=CTc/postgres
test | postgres | UTF8 | C | C |
(7 行记录)
作者: dwm123 发布时间: 2010-12-14
1 连接 mydb 库
psql mydb postgres
2 查看表属性
\d weather
把第二步的结果打印出来
作者: tanfeng3 发布时间: 2010-12-14
1 连接 mydb 库
psql mydb postgres
2 查看表属性
\d weather
把第二步的结果打印出来
作者: tanfeng3 发布时间: 2010-12-14
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28