简体   繁体   中英

Multiple Select Statements and PSQL

I am trying to understand how to run multiple select statements from a script and then output the matches to different text files. I have about 20 different select statements.

text editor; Sublime 2

PSQL; 9.3.5.0

Here is my script;

   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;

Here is the error message I receive when I try to run my script called test.3.sql

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

Any help is appreciated.

Figured it out... finally

    \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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM