PgSQL diff patch from wries
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Parser / PostgreSQL.pm
index 09a8815..525582c 100644 (file)
@@ -154,6 +154,9 @@ statement : create
   | connect
   | update
   | set
+  | select
+  | copy
+  | readin_symbol
   | <error>
 
 connect : /^\s*\\\connect.*\n/
@@ -172,6 +175,9 @@ revoke : /revoke/i WORD(s /,/) /on/i TABLE(?) table_name /from/i name_with_opt_q
         }
     }
 
+revoke : /revoke/i WORD(s /,/) /on/i SCHEMA(?) schema_name /from/i name_with_opt_quotes(s /,/) ';'
+    { 1 }
+
 grant : /grant/i WORD(s /,/) /on/i TABLE(?) table_name /to/i name_with_opt_quotes(s /,/) ';'
     {
         my $table_info  = $item{'table_name'};
@@ -184,6 +190,9 @@ grant : /grant/i WORD(s /,/) /on/i TABLE(?) table_name /to/i name_with_opt_quote
         }
     }
 
+grant : /grant/i WORD(s /,/) /on/i SCHEMA(?) schema_name /to/i name_with_opt_quotes(s /,/) ';'
+    { 1 }
+
 drop : /drop/i /[^;]*/ ';'
 
 string :
@@ -462,6 +471,8 @@ table_name : schema_qualification(?) name_with_opt_quotes {
 
   schema_qualification : name_with_opt_quotes '.'
 
+schema_name : name_with_opt_quotes
+
 field_name : name_with_opt_quotes
 
 name_with_opt_quotes : double_quote(?) NAME double_quote(?) { $item[2] }
@@ -594,7 +605,8 @@ pg_data_type :
 parens_value_list : '(' VALUE(s /,/) ')'
     { $item[2] }
 
-parens_word_list : '(' WORD(s /,/) ')'
+
+parens_word_list : '(' name_with_opt_quotes(s /,/) ')'
     { $item[2] }
 
 field_size : '(' num_range ')' { $item{'num_range'} }
@@ -765,6 +777,9 @@ alter : alter_table table_name DROP /constraint/i NAME restrict_or_cascade ';'
 alter : alter_table table_name /owner/i /to/i NAME ';'
     { 1 }
 
+alter : alter_sequence NAME /owned/i /by/i column_name ';'
+    { 1 }
+
 storage_type : /(plain|external|extended|main)/i
 
 alter_default_val : SET default_val 
@@ -832,6 +847,8 @@ add_column : ADD COLUMN(?)
 
 alter_table : ALTER TABLE ONLY(?)
 
+alter_sequence : ALTER SEQUENCE 
+
 drop_column : DROP COLUMN(?)
 
 alter_column : ALTER COLUMN(?)
@@ -841,6 +858,24 @@ rename_column : /rename/i COLUMN(?)
 restrict_or_cascade : /restrict/i | 
     /cascade/i
 
+# Handle functions that can be called
+select : SELECT select_function ';' 
+    { 1 }
+
+# Read the setval function but don't do anything with it because this parser
+# isn't handling sequences
+select_function : schema_qualification(?) /setval/i '(' VALUE /,/ VALUE /,/ /(true|false)/i ')' 
+    { 1 }
+
+# Skipping all COPY commands
+copy : COPY WORD /[^;]+/ ';' { 1 }
+    { 1 }
+
+# The "\." allows reading in from STDIN but this isn't needed for schema
+# creation, so it is skipped.
+readin_symbol : '\.'
+    {1}
+
 #
 # End basically useless stuff. - ky
 #
@@ -849,7 +884,7 @@ create_table : CREATE TABLE
 
 create_index : CREATE /index/i
 
-default_val  : DEFAULT /(\d+|'[^']*'|\w+\(.*?\))|\w+/
+default_val  : DEFAULT /(\d+|'[^']*'|\w+\(.*\))|\w+/
     { 
         my $val =  defined $item[2] ? $item[2] : '';
         $val    =~ s/^'|'$//g; 
@@ -901,8 +936,16 @@ COLUMN : /column/i
 
 TABLE : /table/i
 
+SCHEMA : /schema/i
+
 SEMICOLON : /\s*;\n?/
 
+SEQUENCE : /sequence/i
+
+SELECT : /select/i
+
+COPY : /copy/i
+
 INTEGER : /\d+/
 
 WORD : /\w+/
@@ -993,7 +1036,7 @@ sub parse {
                 name   => $idata->{'name'},
                 type   => uc $idata->{'type'},
                 fields => $idata->{'fields'},
-            ) or die $table->error;
+            ) or die $table->error . ' ' . $table->name;
         }
 
         for my $cdata ( @{ $tdata->{'constraints'} || [] } ) {