在postgresql(windows版本9.2.4)中比较日期时,我一直面临着一个奇怪的场景。

我有一个列在我的表说update_date类型的时间戳没有时区。客户端可以在该字段中只搜索日期(例如:2013-05-03)或日期(例如:2013-05-03 12:20:00)。

该列的值为当前所有行的时间戳,日期部分2013-05-03相同,但时间部分不同。

当我比较这一列时,我得到了不同的结果。比如:

select * from table where update_date >= '2013-05-03' AND update_date <= '2013-05-03' -> No results

select * from table where update_date >= '2013-05-03' AND update_date < '2013-05-03' -> No results

select * from table where update_date >= '2013-05-03' AND update_date <= '2013-05-04' -> results found

select * from table where update_date >= '2013-05-03' -> results found

我的问题是我如何能使第一个查询可能得到结果,我的意思是为什么第三个查询工作,而不是第一个?

是否有一种方法使用SQL列出给定表的所有外键?我知道表名/模式,我可以把它插入。

这个问题是,当邮政局长在后台运行您的查询时,如何杀死或停止它?

例如,您的shell或任何前端可能由于网络问题而断开连接,您不能使用ctrl-D杀死它,但后台邮政管理员仍在运行您的查询。如何杀死它?

我想给一个用户在数据库上的所有权限,而不使它成为管理员。 我想这样做的原因是,目前DEV和PROD是同一集群上的不同db,所以我不希望用户能够更改生产对象,但必须能够更改DEV上的对象。

我试着:

grant ALL on database MY_DB to group MY_GROUP;

但它似乎没有给予任何许可。

然后我试着:

grant all privileges on schema MY_SCHEMA to group MY_GROUP;

它似乎允许我创建对象,但不允许我在该模式上查询\删除属于其他用户的对象

我可以继续在MY_SCHEMA上给用户USAGE权限,但是它会抱怨没有对表的权限…

所以我想我的问题是:是否有任何简单的方法将所有权限赋予一个用户在数据库上?

我在PostgreSQL 8.1.23工作。

我运行下面的sql脚本在我的数据库:

create table cities (
id serial primary key,
name text not null
);

create table reports (
id serial primary key,
cityid integer not null references cities(id),
reportdate date not null,
reporttext text not null
);

create user www with password 'www';

grant select on cities to www;
grant insert on cities to www;
grant delete on cities to www;

grant select on reports to www;
grant insert on reports to www;
grant delete on reports to www;

grant select on cities_id_seq to www;
grant insert on cities_id_seq to www;
grant delete on cities_id_seq to www;

grant select on reports_id_seq to www;
grant insert on reports_id_seq to www;
grant delete on reports_id_seq to www;

当用户www试图:

insert into cities (name) values ('London');

我得到以下错误:

ERROR: permission denied for sequence cities_id_seq

我知道问题出在连续类型上。这就是为什么我将*_id_seq的选择、插入和删除权限授予www。但这并不能解决我的问题。我错过了什么?

在MS SQL-Server,我可以做:

SELECT ISNULL(字段,'空'

但是在PostgreSQL中,我得到了一个语法错误。我如何模拟ISNULL()功能?

我通过Ruby宝石“续集”使用PostgreSQL。

我要四舍五入到小数点后两位。

这是我的代码:

SELECT ROUND(AVG(some_column),2)    
FROM table

我得到以下错误:

PG::Error: ERROR:  function round(double precision, integer) does 
not exist (Sequel::DatabaseError)

当我运行以下代码时,我没有得到错误:

SELECT ROUND(AVG(some_column))
FROM table

有人知道我哪里做错了吗?

我在PostgreSQL中有一个有很多列的表,我想添加一个自动递增的主键。

我试图创建一个名为BIGSERIAL类型id的列,但pgadmin响应一个错误:

错误:序列必须与它所链接的表具有相同的所有者。

有人知道如何解决这个问题吗?我如何在PostgreSQL中添加或创建一个自动递增的主键而不重新创建表?

重新启动我的Mac,我得到了可怕的Postgres错误:

psql: could not connect to server: No such file or directory
 Is the server running locally and accepting
 connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

发生这种情况的原因是由于一个无关的问题,我的macbook完全死机了,我不得不使用电源按钮进行硬重启。重启后,由于这个错误,我无法启动Postgres。

我正在尝试为Ruby安装PostgreSQL的pg gem。

我发出了以下命令:

gem install pg

我使用RVM安装Ruby 1.9.2。

上面的命令显示了以下错误。

错误是:

Building native extensions.  This could take a while...

ERROR:  Error installing pg:

ERROR: Failed to build gem native extension.

/home/User/.rvm/rubies/ruby-1.9.2-preview3/bin/ruby extconf.rb

checking for pg_config... yes
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)

*** extconf.rb failed ***

Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
 --with-opt-dir
 --without-opt-dir
 --with-opt-include
 --without-opt-include=${opt-dir}/include
 --with-opt-lib
 --without-opt-lib=${opt-dir}/lib
 --with-make-prog
 --without-make-prog
 --srcdir=.
 --curdir
 --ruby=/home/User/.rvm/rubies/ruby-1.9.2-preview3/bin/ruby
 --with-pg
 --without-pg
 --with-pg-config
 --without-pg-config
 --with-pg-dir
 --without-pg-dir
 --with-pg-include
 --without-pg-include=${pg-dir}/include
 --with-pg-lib
 --without-pg-lib=${pg-dir}/lib
 --enable-static-build
 --disable-static-build
 --with-pqlib
 --without-pqlib
 --with-libpqlib
 --without-libpqlib
 --with-ms/libpqlib
 --without-ms/libpqlib

Gem files will remain installed in /home/user/.rvm/gems/ruby-1.9.2-preview3/gems/pg-0.9.0 for inspection.

Results logged to /home/user/.rvm/gems/ruby-1.9.2-preview3/gems/pg-0.9.0/ext/gem_make.out

我不知道是什么错误…