create schema keyword_test;
set search_path to keyword_test;
/* cast */
create table cast(cast int);
insert into cast values(1);
select cast from cast;
 cast 
------
    1
(1 row)

/* last_day */
create table last_day(last_day int);
insert into last_day values(1);
select last_day from last_day;
 last_day 
----------
        1
(1 row)

/* less */
create table less(less int);
insert into less values(1);
select less from less;
 less 
------
    1
(1 row)

/* modify */
create table modify(modify int);
insert into modify values(1);
select modify from modify;
 modify 
--------
      1
(1 row)

/* modify */
create table modify(modify int);
ERROR:  relation "modify" already exists in schema "keyword_test"
DETAIL:  creating new table with existing name in the same schema
insert into modify values(1);
select modify from modify;
 modify 
--------
      1
      1
(2 rows)

/* notnull */
create table notnull(notnull int);
insert into notnull values(1);
select notnull from notnull;
 notnull 
---------
       1
(1 row)

/* recyclebin */
create table recyclebin(recyclebin int);
insert into recyclebin values(1);
select recyclebin from recyclebin;
 recyclebin 
------------
          1
(1 row)

/* analyse */
create table analyse(analyse int);
insert into analyse values(1);
select analyse from analyse;
 analyse 
---------
       1
(1 row)

-- analyse unsupported
analyse;
ERROR:  syntax error at or near "analyse"
LINE 1: analyse;
        ^
explain analyse select 1;
ERROR:  syntax error at or near "analyse"
LINE 1: explain analyse select 1;
                ^
analyse verbose;
ERROR:  syntax error at or near "analyse"
LINE 1: analyse verbose;
        ^
alter table analyse analyse /* unsupported analyse keyword*/ verbose partition all;
ERROR:  syntax error at or near "analyse"
LINE 1: alter table analyse analyse /* unsupported analyse keyword*/...
                            ^
/* buckets */
create table buckets(buckets int);
insert into buckets values(1);
select buckets from buckets;
 buckets 
---------
       1
(1 row)

select * from buckets buckets(1,2,3,4) /* unsupported buckets keyword*/;
ERROR:  syntax error at or near "1"
LINE 1: select * from buckets buckets(1,2,3,4) /* unsupported bucket...
                                      ^
alter node group test copy buckets from test2 /* unsupported */;
ERROR:  syntax error at or near "copy"
LINE 1: alter node group test copy buckets from test2 /* unsupported...
                              ^
create node group mergegroup1 with (datanode1, datanode3, datanode5); /* unsupported */
ERROR:  syntax error at or near "group"
LINE 1: create node group mergegroup1 with (datanode1, datanode3, da...
                    ^
/* compact */
create table compact(compact int);
insert into compact values(1);
select compact from compact;
 compact 
---------
       1
(1 row)

analyze compact test/* table name */;
ERROR:  syntax error at or near "test"
LINE 1: analyze compact test/* table name */;
                        ^
-- compact unsupported
create table test(id int) with (row_format=compact);
ERROR:  unrecognized parameter "row_format"
/* rownum */
create table rownum(rownum int);
insert into rownum values(1);
select rownum from rownum;
 rownum 
--------
      1
(1 row)

select rownum rownum from rownum; /* rownum can be alias name */
 rownum 
--------
      1
(1 row)

/* user */
create table user(user int);
insert into user values(1);
select user from user;
 user 
------
    1
(1 row)

select user(); --success
--?.*
--?.*
--?.*
(1 row)

select user; --failed
ERROR:  column "user" does not exist
LINE 1: select user;
               ^
CONTEXT:  referenced column: user
create user user identified by 'xxxx@xx1xx'; -- username user can be created
create user mapping for user server mot_server; -- username: user
create user mapping for current_user server mot_server; -- username: current_user
select count(distinct usename) from pg_user_mappings where usename in ('user', current_user()); -- expected: 2
 count 
-------
     2
(1 row)

alter table user disable trigger user; -- success: disable user trigger
alter table user disable trigger "user"; -- failed: cant not find trigger(named user)
/* sysdate */
create table sysdate(sysdate int);
insert into sysdate values(1);
select sysdate from sysdate;
 sysdate 
---------
       1
(1 row)

/* body */
create table body(body int);
insert into body values(1);
select body from body;
 body 
------
    1
(1 row)

/* collation */
create table collation(collation int);
insert into collation values(1);
select collation from collation;
 collation 
-----------
         1
(1 row)

/* minus */
create table minus(minus int);
insert into minus values(1);
select minus from minus;
 minus 
-------
     1
(1 row)

/* any */
create table any(any int);
insert into any values(1);
select any from any;
 any 
-----
   1
(1 row)

/* do */
create table do(do int);
insert into do values(1);
select do from do;
 do 
----
  1
(1 row)

-- binary/prior do 
create rule "test" as on select to t1 where binary do instead select * from t2; -- unsupported
ERROR:  syntax error at or near "instead"
LINE 1: ...te rule "test" as on select to t1 where binary do instead se...
                                                             ^
create rule "test" as on select to t1 where prior do instead select * from t2; -- unsupported
ERROR:  syntax error at or near "instead"
LINE 1: ...ate rule "test" as on select to t1 where prior do instead se...
                                                             ^
create rule "test" as on select to t1 where binary do do instead select * from t2; -- t1 no exists
ERROR:  relation "t1" does not exist
create rule "test" as on select to t1 where prior do do instead select * from t2; -- t1 no exists
ERROR:  relation "t1" does not exist
create rule "test" as on select to t1 where (binary) do instead select * from t2; -- t1 no exists
ERROR:  syntax error at or near ")"
LINE 1: ...reate rule "test" as on select to t1 where (binary) do inste...
                                                             ^
create rule "test" as on select to t1 where (prior) do instead select * from t2; -- t1 no exists
ERROR:  syntax error at or near ")"
LINE 1: create rule "test" as on select to t1 where (prior) do inste...
                                                          ^
create rule "test" as on select to t1 where test do instead select * from t2; -- t1 no exists
ERROR:  relation "t1" does not exist
create rule "test" as on select to t1 where 1=1 do instead select * from t2; -- t1 no exists
ERROR:  relation "t1" does not exist
/* end */
create table end(end int);
insert into end values(1);
select end from end;
 end 
-----
   1
(1 row)

select case when end then binary else binary end from end; -- unsupported
ERROR:  syntax error at or near "else"
LINE 1: select case when end then binary else binary end from end;
                                         ^
select case when end then binary else (binary) end from end; -- binary un exists
ERROR:  syntax error at or near "else"
LINE 1: select case when end then binary else (binary) end from end;
                                         ^
select case when end then binary end else binary end end from end;
 end  
------
 \x31
(1 row)

/* only */
create table only(only int);
insert into only values(1);
select only from only;
 only 
------
    1
(1 row)

select * from only test; -- scan only(alias: test) table
 only 
------
    1
(1 row)

select * from only (test); -- scan test(scan InhOption: INH_NO) table 
ERROR:  relation "test" does not exist on datanode1
LINE 1: select * from only (test);
                            ^
/* verbose */
create table verbose(verbose int);
insert into verbose values(1);
select verbose from verbose;
 verbose 
---------
       1
(1 row)

-- cluster
cluster verbose verbose; --unsupported
ERROR:  syntax error at or near "verbose"
LINE 1: cluster verbose verbose;
                        ^
cluster verbose; --supported
ERROR:  there is no previously clustered index for table "verbose"
cluster (verbose) verbose; --supported
ERROR:  there is no previously clustered index for table "verbose"
cluster verbose partition (test); --supported
ERROR:  table is not partitioned
cluster (verbose) verbose partition (test); --supported
ERROR:  table is not partitioned
cluster; --supported
cluster (verbose); --supported
cluster (verbose) verbose on verbose; --supported
ERROR:  "verbose" is not an index
cluster verbose on verbose; --supported
ERROR:  "verbose" is not an index
-- vacuum
vacuum full verbose partition (test); --supported
ERROR:  partition "test" of relation "verbose" does not exist
vacuum full verbose subpartition (test); --supported
ERROR:  subpartition "test" of relation "verbose" does not exist
VACUUM full analyze verbose; --supported
vacuum (full,freeze,verbose) verbose; --supported
--?.*
--?.*
DETAIL:  0 dead row versions cannot be removed yet.
CPU 0.00s/0.00u sec elapsed 0.00 sec.
vacuum verbose;
vacuum full verbose;
vacuum full freeze verbose; --unsupported
ERROR:  syntax error at or near "verbose"
LINE 1: vacuum full freeze verbose;
                           ^
vacuum full freeze verbose compact; --unsupported
ERROR:  syntax error at or near "verbose"
LINE 1: vacuum full freeze verbose compact;
                           ^
-- analyse
analyze verbose; --supported
analyze verbose verbose; --unsupported
ERROR:  syntax error at or near "verbose"
LINE 1: analyze verbose verbose;
                        ^
analyze (verbose) verbose; --supported
--?.*
--?.*
analyze verbose; --supported
analyze (verbose) verbose; --supported
--?.*
--?.*
analyze foreign tables; --supported
WARNING:  Running analyze on table/tables reside in HDFS directly from data node is not supported.
analyze (verbose) foreign tables; --supported
WARNING:  Running analyze on table/tables reside in HDFS directly from data node is not supported.
analyze verbose foreign tables; --unsupported
ERROR:  syntax error at or near "foreign"
LINE 1: analyze verbose foreign tables;
                        ^
create index verbose_index on verbose(verbose);
-- unreserved keyword: ast, PARTITIONING, REPAIR, ROWTYPE_P, 
create table ast(ast int);
create table PARTITIONING(PARTITIONING int);
create table REPAIR(REPAIR int);
create table ROWTYPE(ROWTYPE int);
-- col_name_keyword
create table ttt_test(TIMESTAMPADD int);
--type func keyword
create FUNCTION sounds() RETURNS int as 'select 1' language sql;
/* excluded */
create table excluded(excluded int);
insert into excluded values(1);
select excluded from excluded;
 excluded 
----------
        1
(1 row)

insert into excluded values (1) on duplicate key update excluded = excluded.excluded;
insert into excluded select 1 on duplicate key update excluded = excluded + 1;
-- name test
CREATE TABLE x (id int);
CREATE FUNCTION fn_x_before () RETURNS TRIGGER AS '
  BEGIN
		NEW.e := ''before trigger fired''::text;
		return NEW;
	END;
' LANGUAGE plpgsql;
CREATE TRIGGER "user" AFTER INSERT ON x FOR EACH ROW EXECUTE PROCEDURE fn_x_before(); -- unsupported name
ERROR:  user cannot be trigger name
CREATE TRIGGER test AFTER INSERT ON x FOR EACH ROW EXECUTE PROCEDURE fn_x_before();
ALTER TRIGGER test ON x RENAME TO user; -- unsupported name
ERROR:  user cannot be trigger name
-- shrink
create table shrink(shrink int);
insert into shrink values(1);
select shrink from shrink;
 shrink 
--------
      1
(1 row)

select shrink performance from shrink performance;
 performance 
-------------
           1
(1 row)

CREATE FUNCTION shrink (s CHAR(20)) RETURNS int
CONTAINS SQL AS $$ select 1 $$ ;
-- performance
create table performance(performance int);
insert into performance values(1);
select performance from performance;
 performance 
-------------
           1
(1 row)

select performance shrink from performance shrink;
 shrink 
--------
      1
(1 row)

CREATE FUNCTION performance (s CHAR(20)) RETURNS int
CONTAINS SQL AS $$ select 1 $$ ;
reset search_path;
drop schema keyword_test cascade;
NOTICE:  drop cascades to 33 other objects
DETAIL:  drop cascades to table keyword_test."cast"
drop cascades to table keyword_test.last_day
drop cascades to table keyword_test."less"
drop cascades to table keyword_test."modify"
drop cascades to table keyword_test."notnull"
drop cascades to table keyword_test."recyclebin"
drop cascades to table keyword_test."analyse"
drop cascades to table keyword_test."buckets"
drop cascades to table keyword_test."compact"
drop cascades to table keyword_test."rownum"
drop cascades to table keyword_test."user"
drop cascades to table keyword_test."sysdate"
drop cascades to table keyword_test.body
drop cascades to table keyword_test."collation"
drop cascades to table keyword_test."minus"
drop cascades to table keyword_test."any"
drop cascades to table keyword_test."do"
drop cascades to table keyword_test."end"
drop cascades to table keyword_test."only"
drop cascades to table keyword_test."verbose"
drop cascades to table keyword_test.ast
drop cascades to table keyword_test."PARTITIONING"
drop cascades to table keyword_test."REPAIR"
drop cascades to table keyword_test."ROWTYPE"
drop cascades to table keyword_test.ttt_test
drop cascades to function keyword_test.sounds()
drop cascades to table keyword_test."excluded"
drop cascades to table keyword_test.x
drop cascades to function keyword_test.fn_x_before()
drop cascades to table keyword_test."shrink"
drop cascades to function keyword_test."shrink"(character)
drop cascades to table keyword_test."performance"
drop cascades to function keyword_test."performance"(character)
drop user user cascade;