GVKun编程网logo

Postgres-如何返回缺少计数的0行?(post请求返回200但没有数据)

23

对于Postgres-如何返回缺少计数的0行?感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍post请求返回200但没有数据,并为您提供关于centos7下源码编译安装php支持Postgre

对于Postgres-如何返回缺少计数的0行?感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍post请求返回200但没有数据,并为您提供关于centos 7下源码编译安装php支持PostgreSQL postgresql手册 postgresql官网下载 postgresql视频教、postgres 密码错误:请输入用户“postgres”的密码以连接服务器 - “PostgreSQL 13”、postgresql – CakePHP无法保存到Postgres数据库中,但成功返回、postgresql – OS X上的Postgres找不到postgis扩展控制文件的有用信息。

本文目录一览:

Postgres-如何返回缺少计数的0行?(post请求返回200但没有数据)

Postgres-如何返回缺少计数的0行?(post请求返回200但没有数据)

我几年(2003-2008年)的数据分布不均(写日期)。我想查询给定开始日期和结束日期的数据,按PostgreSQL
8.3(http://www.postgresql.org/docs中支持的任何间隔(天,周,月,季度,年)将数据分组/8.3/static/functions-datetime.html#FUNCTIONS-
DATETIME-TRUNC)。

问题在于,某些查询会在要求的时间内连续提供结果,如下所示:

select to_char(date_trunc(''month'',date), ''YYYY-MM-DD''),count(distinct post_id) from some_table where category_id=1 and entity_id = 77  and entity2_id = 115 and date <= ''2008-12-06'' and date >= ''2007-12-01'' group by date_trunc(''month'',date) order by date_trunc(''month'',date);          to_char   | count         ------------+-------         2007-12-01 |    64         2008-01-01 |    31         2008-02-01 |    14         2008-03-01 |    21         2008-04-01 |    28         2008-05-01 |    44         2008-06-01 |   100         2008-07-01 |    72         2008-08-01 |    91         2008-09-01 |    92         2008-10-01 |    79         2008-11-01 |    65        (12 rows)

但是其中一些会因为没有数据而错过一些时间间隔,例如:

select to_char(date_trunc(''month'',date), ''YYYY-MM-DD''),count(distinct post_id) from some_table where category_id=1 and entity_id = 75  and entity2_id = 115 and date <= ''2008-12-06'' and date >= ''2007-12-01'' group by date_trunc(''month'',date) order by date_trunc(''month'',date);        to_char   | count     ------------+-------     2007-12-01 |     2     2008-01-01 |     2     2008-03-01 |     1     2008-04-01 |     2     2008-06-01 |     1     2008-08-01 |     3     2008-10-01 |     2    (7 rows)

所需结果集为:

  to_char   | count ------------+------- 2007-12-01 |     2 2008-01-01 |     2 2008-02-01 |     0 2008-03-01 |     1 2008-04-01 |     2 2008-05-01 |     0 2008-06-01 |     1 2008-07-01 |     0 2008-08-01 |     3 2008-09-01 |     0 2008-10-01 |     2 2008-11-01 |     0(12 rows)

缺少条目的计数为0。

我已经看到了关于堆栈溢出的较早讨论,但是它们似乎并不能解决我的问题,因为我的分组时间是(天,周,月,季度,年)之一,并且由应用程序决定运行时。因此,我猜想像日历表或序列表的左联接之类的方法将无济于事。

我目前的解决方案是使用日历模块填补Python(在Turbogears App中)的这些空白。

有一个更好的方法吗。

答案1

小编典典

您可以使用以下方法创建去年(例如)的所有前几天的列表

select distinct date_trunc(''month'', (current_date - offs)) as date from generate_series(0,365,28) as offs;          date------------------------ 2007-12-01 00:00:00+01 2008-01-01 00:00:00+01 2008-02-01 00:00:00+01 2008-03-01 00:00:00+01 2008-04-01 00:00:00+02 2008-05-01 00:00:00+02 2008-06-01 00:00:00+02 2008-07-01 00:00:00+02 2008-08-01 00:00:00+02 2008-09-01 00:00:00+02 2008-10-01 00:00:00+02 2008-11-01 00:00:00+01 2008-12-01 00:00:00+01

然后,您可以加入该系列。

centos 7下源码编译安装php支持PostgreSQL postgresql手册 postgresql官网下载 postgresql视频教

centos 7下源码编译安装php支持PostgreSQL postgresql手册 postgresql官网下载 postgresql视频教

1. 下载源码

$ mkdir /usr/downloads
$ wget -c http://cn2.php.net/distributions/php-5.6.20.tar.gz
$ tar -xvf php-5.6.20.tar.gz
$ mv php-5.6.20 /usr/local/src
$ cd !$ &amp; cd php-5.6.20
登录后复制

2. 阅读安装指导

$ ls -also
$ less README
$ less INSTALL
登录后复制

3. 安装依赖包

$ yum install apr apr-util apr-devel apr-util-devel prce lynx
登录后复制

4. 安装httpd

$ wget -c http://apache.fayea.com//httpd/httpd-2.4.20.tar.gz
$ tar -xvf httpd-2.4.20.tar.gz
$ cd httpd-2.4.20
$ ./configure \
--prefix=/usr/local/programs/apache2 \
--enable-rewrite \
--enable-so \
--enable-headers \
--enable-expires \
--with-mpm=worker \
--enable-modules=most \
--enable-deflate \
--enable-module=shared
$ make
$ make install
$ cd /usr/local/programs/apache2
$ cp bin/apachectl /etc/init.d/httpd ## 复制启动脚本
$ /etc/init.d/httpd start ## 启动apache服务器,访问http://localhost/
$ egrep -v ''^[ ]*#|^$'' /usr/local/apache2/conf/httpd.conf | nl ## 查看apache服务器的配置
## 将apache加入系统服务
vi /etc/rc.d/rc.local
```
/usr/local/programs/apache2/bin/apachectl start
```
$ cat /etc/rc.local
登录后复制

4. 安装postgresql

立即学习“PHP免费学习笔记(深入)”;

$ yum install readline-devel  ## 安装readline依赖
$ cd /usr/downloads
$ wget -c https://ftp.postgresql.org/pub/source/v9.5.0/postgresql-9.5.0.tar.bz2
$ tar -xvf postgresql-9.5.0.tar.bz2
$ cd postgresql-9.5.0
$ ./configure --prefix=/usr/local/programs/postgresql
$ make
$ su
$ make install
$ /sbin/ldconfig /usr/local/programs/postgresql/lib ## 刷新下共享动态库
$ cd /usr/local/programs/postgresql
$ bin/psql --version  ## 检查运行情况
## 开始对postgresql的配置
$ vi /etc/profile.d/postgresql.sh ## 增加环境变量,不推荐直接在/etc/profile中添加,系统更新升级时会需要merge
``` 
PATH=/usr/local/programs/postgresql:$PATH
export PATH
```
$ source /etc/profile ## 更新环境变量

## 增加用户和其他文件夹
$ adduser postgres
$ passwd postgres 
$ mkdir /usr/local/programs/postgresql/logs
$ mkdir /usr/local/programs/postgresql/data
$ chown postgres /usr/local/programs/postgresql/data
$ su - postgres

## 初始化数据库
$ ./bin/initdb -D ./data
$ ./bin/createdb test
$ ./bin/psql test
## 已有数据库,可导入data文件夹后尝试root访问,假如带密码,可能需要进一步研究下
$ ./bin/postgres -D ./data &gt;./logs/start-log-1.log 2&gt;&amp;1 &amp;
$ ./bin/psql --list  ##列出数据库
## ok,安装完成

## 自定义设置,权限控制等,可以跳过,等熟悉使用后再做
## 编辑数据库配置及权限文件:
$ vi /usr/local/programs/postgresql/data/postgresql.conf   ## 数据库配置文件
$ chown postgres postgresql.conf
$ chmod 644 postgresql.conf
$ vi /usr/local/programs/postgresql/data/pg_hba.conf   ## 权限文件
$ vi /usr/local/programs/postgresql/data/pg_ident.conf

## 设置开机自启动:
$ vi /etc/rc.d/rc.local    ## 添加如下内容
```
/usr/local/programs/postgresql/bin/postgresql start
```
登录后复制

5. 安装php

## 源码已经在第一步中下载,现在开始安装:
$ yum install libxml2 libxml2-devel libpng libpng-devel libjpeg libjpeg-devel freetype freetype-devel
$ ./configure \
--prefix=/usr/local/programs/php \
--with-apxs2=/usr/local/programs/apache2/bin/apxs \
--with-zlib \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-zlib-dir \
--enable-mbstring \
--with-pgsql=/usr/local/programs/postgresql \
--with-pdo-pgsql=/usr/local/programs/postgresql 
$ make
$ make test
&gt; Bug #42718 (unsafe_raw filter not applied when configured as default filter) [ext/filter/tests/bug42718.phpt]  XFAIL REASON: FILTER_UNSAFE_RAW not applied when configured as default filter, even with flags
&gt; Bug #67296 (filter_input doesn''t validate variables) [ext/filter/tests/bug49184.phpt]  XFAIL REASON: See Bug #49184
&gt; Bug #53640 (XBM images require width to be multiple of 8) [ext/gd/tests/bug53640.phpt]  XFAIL REASON: Padding is not implemented yet
&gt; zend multibyte (7) [ext/mbstring/tests/zend_multibyte-07.phpt]  XFAIL REASON: https://bugs.php.net/bug.php?id=66582
&gt; zend multibyte (9) [ext/mbstring/tests/zend_multibyte-09.phpt]  XFAIL REASON: https://bugs.php.net/bug.php?id=66582
&gt;Bug #70470 (Built-in server truncates headers spanning over TCP packets) [sapi/cli/tests/bug70470.phpt]  XFAIL REASON: bug is not fixed yet

## 查阅官方的bug,发现:
&gt; id=66582: status : Closed. Fixed in master (PHP7)
&gt; id=42718: status : Assigned
&gt; id=42718: reference to id=49184, unsolved for many years
## 那就不关心了,直接装吧
$ make install
&gt; You may want to add: /usr/local/programs/php/lib/php to your php.ini include_path

## 那就按它说的设置吧
$ cp php.ini-development /usr/local/programs/php/lib/php.ini
```
include_path = ".;/usr/local/programs/php/lib/php"

## 然后,编辑httpd的设置,确保其能正确解析php文件
```
...
LoadModule php5_module modules/libphp5.so
...
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .php5

...
<ifmodule dir_module>
    DirectoryIndex index.html index.php
</ifmodule>     
```

## 重启httpd,测试
$ cd /usr/local/programs/apache2
$ bin/httpd -h
$ bin/httpd -k stop
$ bin/httpd -f conf/httpd.conf
## 默认设置的www页面在./htdocs/下,那就先去里面建一个测试页面吧
$ vi htdocs/index.php
```
<?php phpinfo(); ?>
```
$ curl http://localhost/index.php |grep postgresql
#ok
登录后复制

后续应该做的事

* 1. 启动时,不需要要手动指定配置文件
* 2. php初始化www目录设置
* 3. php 用户、权限管理等

'').addClass(''pre-numbering'').hide(); $(this).addClass(''has-numbering'').parent().append($numbering); for (i = 1; i '').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了centos 7下源码编译安装php支持PostgreSQL,包括了postgresql,centos 7方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

postgres 密码错误:请输入用户“postgres”的密码以连接服务器 - “PostgreSQL 13”

postgres 密码错误:请输入用户“postgres”的密码以连接服务器 - “PostgreSQL 13”

如何解决postgres 密码错误:请输入用户“postgres”的密码以连接服务器 - “PostgreSQL 13”?

我与 postgres 的连接有问题,我正在通过 EDB 安装程序(版本 13.2)在 Windows 10 上进行安装。我按照它安装好的所有步骤进行操作,但是当我尝试使用 pgadmin 输入默认数据库时,我总是遇到此错误:

Please enter the password for the user ''postgres'' to connect the server - "Postgresql 13"

在安装过程中 postgres 要求我指定我的主密码。然后当安装完成并打开我的 pgadmin 时,它再次要求我输入主密码,所以我做到了并且我能够成功登录但是当我尝试打开默认数据库时,当它要求我输入 posgres 用户的密码时,我尝试使用我的主密码但没有用

我安装和卸载它很多次都没有成功。我也尝试过 this solution 所以我确实将 pg_hba.config 中的方法从 scram-sha-256 更改为 trust 但是当我执行此命令 psql -U postgres 时它再次要求我输入密码

请帮忙

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

postgresql – CakePHP无法保存到Postgres数据库中,但成功返回

postgresql – CakePHP无法保存到Postgres数据库中,但成功返回

以前有人遇到过这个问题吗?

在CakePHP中,我有这个.

$this->loadModel(''BankBalance'');
    $data = array("BankBalance"=> array(bla bla bla...);
    $this->BankBalance->save($data);
    $log = $this->BankBalance->getDataSource()->getLog(false,false); debug($log);

并且调试将此返回给我

array(
''log'' => array(
    (int) 0 => array(
        ''query'' => ''BEGIN'',''params'' => array(),''affected'' => null,''numRows'' => null,''took'' => null
    ),(int) 1 => array(
        ''query'' => ''INSERT INTO bla bla bla...)'',''affected'' => (int) 1,''numRows'' => (int) 1,''took'' => (float) 7
    ),(int) 2 => array(
        ''query'' => ''COMMIT'',''took'' => (float) 7
    )
),''count'' => (int) 3,''time'' => (float) 14)

实际上,尽管返回了成功的消息,但未插入行.但是如果我复制生成的sql并运行它,它确实会插入到表中.
我也试过使用savemany,它没有执行INSERTion,但仍然给我回复了成功的消息.

CakePHP中没有错误日志. updateall适用于UPDATE.现在我正在寻找sql INSERT

我甚至不能做 – >保存到一个简单的表中,单个字段(字符变化(50)),没有触发器,没有.返回成功消息,但没有物理数据插入表中.

解决方法

如果要插入数据,则需要按put创建一个新数据

$this->BankBalance->create();

之前的任何地方(最好的开始)

$this->BankBalance->save($data);

并把

if($this->BankBalance->save($data)){
    $log = $this->BankBalance->getDataSource()->getLog(false,false);
    debug($log);
}

代替

$this->BankBalance->save($data);
$log = $this->BankBalance->getDataSource()->getLog(false,false); debug($log);

知道是否成功保存

postgresql – OS X上的Postgres找不到postgis扩展控制文件

postgresql – OS X上的Postgres找不到postgis扩展控制文件

使用mac OSX Yosemite 10.10.1.我用自制软件卸载并重新安装了postgres和postgis.我知道postgres正在查找postgis控制文件的错误位置.还注意到’哪个psql’路径似乎不正确.我如何/在哪里解决这个问题?

Psql

(9.4.0,server 9.3.5)

ERROR:  Could not open extension control file "/usr/local/Cellar/postgresql/9.3.5_1/share/postgresql/extension/postgis.control": No such file or directory

找到/ usr -name postgis.control

/usr/local/Cellar/postgresql/9.4.0/share/postgresql/extension/postgis.control

哪个psql

/usr/local/bin/psql

哪个pg_config

/usr/local/bin/pg_config

brew info postgis

postgis: stable 2.1.5,HEAD
http://postgis.net
/usr/local/Cellar/postgis/2.1.5 (45 files,8.6M) *
  Built from source
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/postgis.rb

brew info postgres

postgresql: stable 9.4.0 (bottled)
http://www.postgresql.org/
Conflicts with: postgres-xc
/usr/local/Cellar/postgresql/9.4.0 (3049 files,74M) *
  Poured from bottle
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/postgresql.rb

.bashrc和.bash_profile都有

export PGDATA='/usr/local/Cellar/postgresql/9.4.0/bin/postgres'
alias postgres-log='cd /usr/local/var/postgres/ && subl server.log'

mdfind -name“postgres”| grep -G“postgres $”

/usr/local/Cellar/postgresql/9.4.0/bin/postgres
/usr/local/var/postgres
/Users/lionelramos/macports/var/macports/sources/rsync.macports.org/release/tarballs/ports/ruby/rb-postgres

看起来除了自制软件版本之外,我还有不同的postgres本地版本.

我是如何解决我的问题的:

>我使用brew卸载postgres 9.3.5_1卸载了postgres 9.3.5_1.
>我用brew卸载postgis卸载了postgis
>确保我只使用brew信息postgres安装了postgres 9.4
>确保psql命令有效.
>我用brew install postgis重新安装了postgis.

这解决了我的问题.如果您遇到第4步的问题,则可能需要使用initdb或createdb命令来创建所需的数据库.

我们今天的关于Postgres-如何返回缺少计数的0行?post请求返回200但没有数据的分享已经告一段落,感谢您的关注,如果您想了解更多关于centos 7下源码编译安装php支持PostgreSQL postgresql手册 postgresql官网下载 postgresql视频教、postgres 密码错误:请输入用户“postgres”的密码以连接服务器 - “PostgreSQL 13”、postgresql – CakePHP无法保存到Postgres数据库中,但成功返回、postgresql – OS X上的Postgres找不到postgis扩展控制文件的相关信息,请在本站查询。

本文标签: