Questions in category: PostgreSQL (PostgreSQL)
软件 >> PostgreSQL
<[1] [2] >

11. psql 的使用

Posted by haifeng on 2014-10-23 12:22:20 last update 2014-10-27 14:41:44 | Answers (0) | 收藏


登录 PostgreSQL, 并指定到数据库 dbname

psql -h 127.0.0.1 -U username -d dbname


将文件 filename 中的内容导入到数据库  dbname

psql -h localhost -d dbname -U username -f filename

 

12. PostgreSQL 中的基本操作

Posted by haifeng on 2014-10-13 17:59:16 last update 2014-12-01 11:28:57 | Answers (0) | 收藏


与 MySQL 进行对比

mysql: SHOW TABLES
postgresql: \d
postgresql: SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';

mysql: SHOW DATABASES
postgresql: \l
postgresql: SELECT datname FROM pg_database;

mysql: SHOW COLUMNS
postgresql: \d table
postgresql: SELECT column_name FROM information_schema.columns WHERE table_name ='table';

mysql: DESCRIBE TABLE
postgresql: \d+ table
postgresql: SELECT column_name FROM information_schema.columns WHERE table_name ='table';

 


更改表的结构使用 ALTER TABLE 语句

1. 增加一个名为 avatar 的属性 (avatar: 头像)

ALTER TABLE userinfo ADD COLUMN avatar varchar(255);

2. 删除刚才建的属性 avatar

ALTER TABLE userinfo DROP COLUMN avatar;


http://www.linuxscrew.com/2009/07/03/postgresql-show-tables-show-databases-show-columns/

http://blog.163.com/ruihuadesunny@126/blog/static/39026191200952231259710/

13. Archlinux 下安装 PostgreSQL

Posted by haifeng on 2014-09-21 18:42:39 last update 2014-09-21 18:46:14 | Answers (0) | 收藏


首先, 可能要执行

$ sudo pacman -Sy

以同步软件包数据库

然后执行

$ sudo pacman -S postgresql

为了方便管理, 我们还将安装 phpPgAdmin

$ sudo pacman -S phppgadmin


创建一个用户

$ createuser -s -U postgres --interactive
输入要增加的角色名称: haifeng
createuser: 无法联接到数据库 postgres: 无法联接到服务器: 没有那个文件或目录
    服务器是否在本地运行并且在 Unix 域套接字
    "/run/postgresql/.s.PGSQL.5432"上准备接受联接?


14. 奇怪的问题

Posted by haifeng on 2014-09-03 22:06:22 last update 2014-09-03 22:19:24 | Answers (0) | 收藏


INSERT INTO categories ("name", "parent", "name_en", "stocks_num", "price_in", "price_out", "factory") VALUES ('计算器', 0, 'jsq', , , , '');

使用 pg_last_error() 函数返回:
ERROR: syntax error at or near "," LINE 1: ...rice_out", "factory") VALUES ('计算器', 0, 'jsq', , , , ''); ^

如果使用 pg_admin3, 执行上面的 sql 语句得到

ERROR:  syntax error at or near "insert"
LINE 1: insert INTO categories ("name", "parent", "name_en", "sto...
        ^

 

问题可能出在上面有好几个变量为空, 如果这几个变量均有值的话,则可以顺利插入到数据库中.

<[1] [2] >