小编pot*_*uff的帖子

将postgresql数组打包成行

在PostgreSQL中将数组展开成行的最快方法是什么?即

我们有:

a
-
{1,2}
{2,3,4}
Run Code Online (Sandbox Code Playgroud)

我们需要:

b
- 
1
2
2
3
4
Run Code Online (Sandbox Code Playgroud)

我用的是:

select explode_array(a) as a from a_table;
Run Code Online (Sandbox Code Playgroud)

explode_array在哪里:

create or replace function explode_array(in_array anyarray) returns setof anyelement as
$$
    select ($1)[s] from generate_series(1,array_upper($1, 1)) as s;
$$
Run Code Online (Sandbox Code Playgroud)

有更好的方法吗?

sql arrays postgresql rows

45
推荐指数
3
解决办法
6万
查看次数

HAVING子句如何真正起作用?

我们能够在SQL查询中使用HAVING子句来过滤行组.当我们使用GROUP BY子句时,它以这种方式直接工作.

但是,让我们看看这个查询:

select 1 where 1!=1 having count(*)=0;
Run Code Online (Sandbox Code Playgroud)

(或者为Oracle添加'from dual').

如果HAVING真的进行了组过滤,那么在WHERE之后我们没有任何行,所以我们没有任何组,结果必须是'No row selected'.

但是在PostgreSQL,MySQL和Oracle中,我们得到'1'作为查询的结果.

问题:HAVING如何真正起作用?

SQL小提琴测试:http://www.sqlfiddle.com/#!15/d5407/51

mysql sql oracle postgresql having-clause

5
推荐指数
1
解决办法
162
查看次数

跳过计算数字和表格标题

如何在没有任何自动计算的情况下制作表格和图形标题?

例如:

\begin{table}
    \begin{tabular}{ll}
    \textbf{Name} & \textbf{Description} \\
        Foo & bar \\
        Foo & bar
    \end{tabular}
    \caption{Nice Table a.I.3. Number of table passed in caption, so it don''t need any automatic numeration }
    \label{tab:table}
\end{table}
Run Code Online (Sandbox Code Playgroud)

latex tex caption figure

4
推荐指数
1
解决办法
9912
查看次数

Nginx 和相对路径

在 nginx root 上,我们有这样的文件:

   - test\
       image.jpg
       index.html
   - ...
Run Code Online (Sandbox Code Playgroud)

在 index.html 中有指向 image.jpg 的链接:

<img src='image.jpg'>
Run Code Online (Sandbox Code Playgroud)

在标准的 Nginx 配置中,我们有这样的行(http://nginx.org/ru/docs/http/ngx_http_core_module.html#try_files

   server {
    server_name example.com;
    ...
    try_files $uri $uri/index.html;
   }
Run Code Online (Sandbox Code Playgroud)

对于 URL http://example.com/test/index.html(以及http://example.com/test/)一切都会很好,因为相对路径的基础将是http://example.com/test / 并且我们在这个文件夹中有 image.jpg。

对于http://example.com/test页面将显示,但没有图像。

在这种情况下最好的解决方案是什么?

url nginx relative-path

2
推荐指数
1
解决办法
5279
查看次数

Rails和ip-spoofing

我在Rails 2.3.2上有一个小应用程序,配有nginx + thin(127).OS FreeBSD 7.1,DB - Posgresql.

Twise本周我的应用已经下降了.在日志中我得到类似的东西(每秒约2-50个请求):

/!\ FAILSAFE /!\  Mon Oct 04 20:13:55 +0300 2010
 Status: 500 Internal Server Error
  bad content body
   /usr/home/../../history/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/utils.rb:311:in `parse_multipart'
   /usr/home/../../history/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/request.rb:125:in `POST'
   /usr/home/../../history/vendor/rails/actionpack/lib/action_controller/request.rb:428:in `request_parameters'
   /usr/home/../../history/vendor/rails/actionpack/lib/action_controller/request.rb:381:in `parameters'
   /usr/home/../../history/vendor/rails/actionpack/lib/action_controller/base.rb:1279:in `assign_shortcuts'
   /usr/home/../../history/vendor/rails/actionpack/lib/action_controller/base.rb:518:in `process_without_filters'
Run Code Online (Sandbox Code Playgroud)

要么:

/!\ FAILSAFE /!\ Tue Nov 09 09:24:39 +0200 2010状态:500内部服务器错误IP欺骗攻击?!HTTP_CLIENT_IP ="XX.XX.XX.XX"HTTP_X_FORWARDED_FOR ="192.168.XX.XX,YY.YY.YY.YY"

/usr/home/../../history/vendor/rails/actionpack/lib/action_controller/request.rb:229:in `remote_ip'
/usr/home/../../history/vendor/rails/actionpack/lib/action_controller/base.rb:1372:in `request_origin'
/usr/home/../../history/vendor/rails/actionpack/lib/action_controller/base.rb:1304:in `log_processing_for_request_id'
/usr/home/../../history/vendor/rails/actionpack/lib/action_controller/base.rb:1296:in `log_processing'
/usr/home/../../history/vendor/rails/actionpack/lib/action_controller/base.rb:522:in `process_without_filters'
Run Code Online (Sandbox Code Playgroud)

在该系统进入最大打开文件限制(我猜它通过postgesql会话打开)后,postgresql无法建立新的连接和应用程序下降.

任何建议,我如何保护我的SSpp在这种情况下?

rake ruby-on-rails ddos thin

1
推荐指数
1
解决办法
1065
查看次数