多选语句和PSQL

时间:2014-09-11 06:51:00

标签: sql postgresql psql

我试图了解如何从脚本运行多个select语句,然后将匹配输出到不同的文本文件。我有大约20种不同的选择陈述。

文本编辑器;崇高2

PSQL; 9.3.5.0

这是我的剧本;

   SELECT text 
     FROM eightks
     WHERE other_events = true 
     AND text ~* '(\y(chief executive officer)\y)'
     AND text ~*'(\y(cancer)\y)'             
     \o /Users/XXXX/desktop/cancer.txt;


  SELECT text 
      FROM eightks
      WHERE other_events = true 
      AND text ~* '(\y(chief executive officer)\y)'
      AND text ~*'(\y(killed)\y)'            
      \o /Users/XXXX/desktop/killed.txt;

以下是我尝试运行名为test.3.sql的脚本时收到的错误消息

\i test3.sql;
psql:test3.sql:17: ERROR:  syntax error at or near "SELECT"
LINE 8: SELECT text

感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

想出来......最后

    \o /Users/XXXX/desktop/test.txt
      \qecho first quert
       SELECT text 
       FROM eightks
       WHERE other_events = true 
       AND text ~* '(\y(chief executive officer)\y)'
       AND text ~*'(\y(cancer)\y)';

    \o /Users/XXXX/desktop/sudden.txt;
      SELECT text
      FROM eightks
      WHERE other_events = true 
      AND text ~* '(\y(chief executive officer)\y)'
      AND text ~* '(\y(sudden)\y)';
    \q