Tag: postgresql

如何从命令行为bash自动化创buildPostgres用户

我使用Ubuntu 12.04和Postgress 9.2。 我需要用这个密码创build这个用户,例如 postgres://admin:test101@127.0.0.1:5432 如何从命令行做到这一点? 我需要一个bash脚本自动化。 我有一个新的安装。

在postgres中增加字符变化types的大小而不会丢失数据

我需要增加postgres数据库表中字符变化(60)字段的大小而不会丢失数据。 我有这个命令 alter table client_details alter column name set character varying(200); 该命令是否将字段大小从60增加到200,而不会丢失数据?

如何从string_agg()中以正确的顺序得到结果

例如, CREATE TABLE tblproducts ( productid integer, product character varying(20) ) 是我的桌子 INSERT INTO tblproducts(productid, product)VALUES (1, 'CANDID POWDER 50 GM'); INSERT INTO tblproducts(productid, product)VALUES (2, 'SINAREST P SYP 100 ML'); INSERT INTO tblproducts(productid, product)VALUES (3, 'ESOZ D 20 MG CAP'); INSERT INTO tblproducts(productid, product)VALUES (4, 'HHDERM CREAM 10 GM'); INSERT INTO tblproducts(productid, product)VALUES (5, […]

如何删除postgres中的枚举types值?

如何删除我在postgresql中创build的枚举types值? create type admin_level1 as enum('classifier', 'moderator', 'god'); 例如,我想从列表中删除moderator 。 我似乎无法find文档上的任何内容。 我正在使用Postgresql 9.3.4。

列表Postgres ENUMtypes

build议查询列出ENUMtypes是很好的。 但是,它只是列出了schema和typestypname 。 如何列出实际的ENUM值? 例如,在上面的链接的答案,我想要以下结果 schema type values ————- ——– ——- communication channels 'text_message','email','phone_call','broadcast'

从Now()到Postgresql中的Current_timestamp

在MySQL中,我能够做到这一点: SELECT * FROM table WHERE auth_user.lastactivity > NOW() – 100 现在在postgresql我使用这个查询: SELECT * FROM table WHERE auth_user.lastactivity > CURRENT_TIMESTAMP – 100 但我得到这个错误: operator does not exist: timestamp with time zone – integer 我该如何解决?

如何在Postgres中使用Blob数据types

我在我的rails应用程序中使用Postgresql数据库。 在数据库中存储大文件或数据我在MySql中使用了blob数据types。 对于Postgres哪些数据types,我不得不使用MySql中的blob? 谢谢!

在Postgresql的where子句中使用别名列

我有这样的查询: SELECT jobs.*, (CASE WHEN lead_informations.state IS NOT NULL THEN lead_informations.state ELSE 'NEW' END) as lead_state FROM "jobs" LEFT JOIN lead_informations ON lead_informations.job_id = jobs.id AND lead_informations.mechanic_id = 3 WHERE (lead_state = 'NEW') 这给出了以下错误: PGError: ERROR: column "lead_state" does not exist LINE 1: …s.id AND lead_informations.mechanic_id = 3 WHERE (lead_state… 在MySql中这是有效的,但显然不是在Postgresql中。 从我可以收集,原因是查询的SELECT部分晚于WHERE部分评估。 这个问题有一个共同的解决方法吗?

为什么pg_restore成功返回,但实际上并没有恢复我的数据库?

我有一个Linux服务器上的Postgres 8.4数据库,我已经倾倒使用以下命令: pg_dump –format=c –exclude-table=log –file=/path/to/output my_db 然后,我将创build的文件ftp到我的本地Windows 7计算机上,并尝试使用以下命令将文件恢复到本地Postgres 8.4实例: pg_restore –create –exit-on-error –verbose c:\path\to\file restore命令会生成大量的输出,声称它创build了我的数据库,连接到它,然后按预期创build所有其他表。 但是,当我通过pgAdmin查看本地计算机上的数据库时,恢复的数据库根本不存在。 在尝试排除故障时,我尝试了下面的命令: pg_restore –create –exit-on-error –verbose –host=blahblah –username=no_one c:\path\to\file 当我运行这个命令,即使给出的主机和用户名是完全废话,我仍然从命令完全相同的输出没有任何错误。 有没有人遇到过这个或知道什么可以通过造成这个?

如何使用SQL for循环将行插入数据库?

我正在使用Postgres,并且我有大量需要被插入到数据库中的行,这些行的差别仅在于递增的整数。 原谅可能是一个愚蠢的问题,但我不是一个数据库大师。 是否有可能直接input一个SQL查询,将使用循环编程插入行? 在我想要做的伪代码中的例子: for i in 1..10000000 LOOP INSERT INTO articles VALUES(i) end loop;