<?xml version="1.0" encoding="UTF-8" ?>
<!--
  CAUTION: Do not modify this file directly on it's code unless you know what you are doing.
	   Unexpected results may occur if the code is changed deliberately.
-->
<snippets>
    <snippet id="grant_privs" label="Grant privileges over an object" object="general" parsable="true" placeholders="false">
<![CDATA[[GRANT ] $ob $sp

%if %not {role} %and {owner} %then
 %set {role} {owner}
%else
 %set {role} $oc role $cc
%end

%if %not {signature} %then
 %set {signature} $oc signature $cc
%end

# Unsetting some attributes that can affect the if's below
%unset {table} {view} {column} {sequence} {language}
%unset {usertype} {function} {aggregate} {database}
%unset {schema} {tablespace}

# Defining the an attribute related to object type to avoid bloat the
# code if comparison statements
%set {object-type} true

%if {table} %or {view} %or {column} %or {sequence} %then
  [ SELECT | UPDATE |]
%end

%if {table} %or {view} %or {column} %then
  [ INSERT | REFERENCES |]
%end

%if {table} %then
  [ TRUNCATE |]
%end

%if {table} %or {view} %then
  [ DELETE | TRIGGER |]
%end

%if {sequence} %or {language} %or {schema} %or {usertype} %or {domain} %then
  [ USAGE |]
%end

%if {database} %or {schema} %or {tablespace} %then
  [ CREATE |]
%end

%if {database} %then
  [ CONNECT | TEMPORARY |]
%end

%if {function}  %or {aggregate} %then
  [ EXECUTE |]
%end

[ ALL PRIVILEGES ] $cb

$br
[ON ] {sql-object} $sp {signature} $br
[TO ] $ob $sp {role} [ | PUBLIC ] $cb $sp $ob [ WITH GRANT OPTION ] $cb
$br]]>
    </snippet>

    <snippet id="obj_rename" label="Rename object" object="general" parsable="true" placeholders="false">
<![CDATA[%if ({object-type} != "column") %and ({object-type} != "constraint") %then
 [ALTER ] {sql-object} $sp {signature}
 [ RENAME TO ] $oc new-name $cc $br
%else
 [ALTER TABLE ] {table} [ RENAME ] {sql-object} $sp {name}
 [ TO ] $oc new-name $cc $br
%end]]>
    </snippet>

    <snippet id="revoke_privs" label="Revoke privileges over an object" object="general" parsable="true" placeholders="false">
<![CDATA[[REVOKE ] $ob [ GRANT OPTION FOR ] $cb $ob $sp

%if %not {role} %and {owner} %then
 %set {role} {owner}
%else
 %set {role} $oc role $cc
%end

%if %not {signature} %then
 %set {signature} $oc signature $cc
%end

# Unsetting some attributes that can affect the if's below
%unset {table} {view} {column} {sequence} {language}
%unset {usertype} {function} {aggregate} {database}
%unset {schema} {tablespace}

# Defining the an attribute related to object type to avoid bloat the
# code if comparison statements
%set {object-type} true

%if {table} %or {view} %or {column} %or {sequence} %then
  [ SELECT | UPDATE |]
%end

%if {table} %or {view} %or {column} %then
  [ INSERT | REFERENCES |]
%end

%if {table} %then
  [ TRUNCATE |]
%end

%if {table} %or {view} %then
  [ DELETE | TRIGGER |]
%end

%if {sequence} %or {language} %or {schema} %or {usertype} %or {domain} %then
  [ USAGE |]
%end

%if {database} %or {schema} %or {tablespace} %then
  [ CREATE |]
%end

%if {database} %then
  [ CONNECT | TEMPORARY |]
%end

%if {function}  %or {aggregate} %then
  [ EXECUTE |]
%end

[ ALL PRIVILEGES ] $cb

$br
[ON ] {sql-object} $sp {signature} $br
[FROM ] $ob $sp {role} [ | PUBLIC ] $cb $sp $br
$ob [ CASCADE | RESTRICT ] $cb
$br]]>
    </snippet>

    <snippet id="set_owner" label="Set object's owner" object="general" parsable="true" placeholders="true">
<![CDATA[[ALTER ] {sql-object} $sp {signature} [ OWNER TO ] {owner} $br]]>
    </snippet>

    <snippet id="set_schema" label="Set object's schema" object="general" parsable="true" placeholders="true">
<![CDATA[[ALTER ] {sql-object} $sp {signature} [ SET SCHEMA ] {schema} $br]]>
    </snippet>

    <snippet id="set_tablespace" label="Set object's tablespace" object="general" parsable="true" placeholders="true">
<![CDATA[[ALTER ] {sql-object} $sp {signature} [ SET TABLESPACE ] {tablespace} $br]]>
    </snippet>

    <snippet id="usrmap_create" label="Create user mapping" object="usermapping" parsable="true" placeholders="true">
<![CDATA[[CREATE USER MAPPING ] $ob [ IF NOT EXISTS ] $cb $sp [ FOR ] $ob {owner} [ | USER | PUBLIC ] $cb $br
[SERVER ] {server} $br
$ob [ OPTIONS ( option 'value' ) ] $cb]]>
    </snippet>

    <snippet id="usrmap_alter" label="Alter user mapping" object="usermapping" parsable="true" placeholders="true">
<![CDATA[[ALTER USER MAPPING FOR ] $ob {owner} | USER | PUBLIC $cb $br
$ob [ OPTIONS ( ADD | SET | DROP option 'value' ) ] $cb ]]>
    </snippet>

    <snippet id="agg_create" label="Create aggregate" object="aggregate" parsable="true" placeholders="true">
<![CDATA[[CREATE AGGREGATE ] {name} $sp ({types}) $sp ( $br
[  SFUNC = ] {transition}, $br
[  STYPE = ] {state-type} $br
$ob [ , FINALFUNC = ] {final} $sp $cb $br
$ob [ , INITCOND = ] {initial-cond} $sp $cb $br
$ob [ , SORTOP = ] {sort-op} $sp $cb $br
) $br]]>
    </snippet>

    <snippet id="cast_create" label="Create cast" object="cast" parsable="true" placeholders="true">
<![CDATA[[ CREATE CAST (] {source-type} [ AS ] {destiny-type}) $br
$ob [ WITH FUNCTION ] {function} [ | WITHOUT FUNCTION | INOUT ] $cb $br
$ob [ AS ASSIGNMENT | AS IMPLICIT ] $cb $br]]>
    </snippet>

    <snippet id="coll_clone" label="Create collation from another" object="collation" parsable="true" placeholders="true">
<![CDATA[[CREATE COLLATION ] {name} [ FROM ] {another-collation} $br]]>
    </snippet>

    <snippet id="coll_create" label="Create collation" object="collation" parsable="true" placeholders="true">
<![CDATA[[CREATE COLLATION ] {name} ( $br
$ob [ LOCALE = ] {locale} [, ] $cb $br
$ob [ LC_COLLATE = ] {lc-collate}[, ] $cb $br
$ob [ LC_CTYPE = ] {lc-ctype} $sp $cb
) $br]]>
    </snippet>

    <snippet id="col_create" label="Create column" object="column" parsable="true" placeholders="true">
<![CDATA[[ALTER TABLE IF EXISTS ] {table} $br
[ADD COLUMN ] {name} $sp {type} $sp $ob [ COLLATE ] {collation} $sp $cb $sp $ob
[ DEFAULT ] {default-value} $cb $sp $ob [ NOT NULL ] $cb $br]]>
    </snippet>

    <snippet id="col_dropdef" label="Drop a column's default value" object="column" parsable="true" placeholders="true">
<![CDATA[[ALTER TABLE IF EXISTS ] {table} $br
[ALTER COLUMN ] {name} [ DROP DEFAULT] $br]]>
    </snippet>

    <snippet id="col_dropnotnull" label="Drop a column's NOT NULL constraint" object="column" parsable="true" placeholders="true">
<![CDATA[[ALTER TABLE IF EXISTS ] {table} $br
[ALTER COLUMN ] {name} [ DROP NOT NULL] $br]]>
    </snippet>

    <snippet id="col_setdef" label="Set a column's default value" object="column" parsable="true" placeholders="true">
<![CDATA[[ALTER TABLE IF EXISTS ] {table} $br
[ALTER COLUMN ] {name} [ SET DEFAULT ] {default-value} $br]]>
    </snippet>

    <snippet id="col_setnotnull" label="Set a column's NOT NULL constraint" object="column" parsable="true" placeholders="true">
<![CDATA[[ALTER TABLE IF EXISTS ] {table} $br
[ALTER COLUMN ] {name} [ SET NOT NULL] $br]]>
    </snippet>

    <snippet id="col_settype" label="Change a column's data type" object="column" parsable="true" placeholders="true">
<![CDATA[[ALTER TABLE IF EXISTS ] {table} $br
[ALTER COLUMN ] {name} [ TYPE ] {type} $sp $ob [ COLLATE ] {collation} $sp $cb $br]]>
    </snippet>

    <snippet id="ck_create" label="Create CHECK constraint" object="constraint" parsable="true" placeholders="true">
<![CDATA[[ALTER TABLE IF EXISTS ] {table} $br
[ADD CONSTRAINT ] {name} [ CHECK (] {expression} ) $br]]>
    </snippet>

    <snippet id="ex_create" label="Create EXCLUDE constraint" object="constraint" parsable="true" placeholders="true">
<![CDATA[[ALTER TABLE IF EXISTS ] {table} $br
[ADD CONSTRAINT ] {name} [ EXCLUDE ] $br
$ob [ USING ] {index-type} $cb $br
$br

[ -- Exclude element(s) configuration ] $br
$ob $sp {column} [ | ] ({expression}) $sp $cb $sp $ob $sp {opclass} $sp $cb
$sp $ob [ ASC | DESC ] $cb $sp $ob [ NULLS FIRST | NULLS LAST ] $cb $br
[ WITH ] {operator} $br

$br
$ob [ USING INDEX TABLESPACE ] {tablespace} $sp $cb $br
$ob [ WHERE (] {predicate} ) $cb $br]]>
    </snippet>

    <snippet id="fk_clone" label="Clones FOREIGN KEY constraint" object="constraint" parsable="true" placeholders="false">
<![CDATA[[ALTER TABLE IF EXISTS ] {table} $br
[ADD CONSTRAINT ] {name} [ FOREIGN KEY (] {src-columns} ) $br
[REFERENCES ] {ref-table} $sp ({dst-columns}) $br
{comparison-type} $br
[ON DELETE ] {del-action} $br
[ON UPDATE ] {upd-action} $br

%if {deferrable} %then
 DEFERRABLE $sp {defer-type}
%else
 [NOT DEFERRABLE]
%end

$br]]>
    </snippet>

    <snippet id="fk_create" label="Create FOREIGN KEY constraint" object="constraint" parsable="true" placeholders="true">
<![CDATA[[ALTER TABLE IF EXISTS ] {table} $br
[ADD CONSTRAINT ] {name} [ FOREIGN KEY (] {src-columns} ) $br
[REFERENCES ] {ref-table} $sp ({ref-columns}) $br

$br
[-- Matching configuration ] $br
MATCH FULL | MATCH PARTIAL | MATCH SIMPLE $br

$br
[-- DELETE and UPDATE actions: NO ACTION | RESTRICT | CASCADE | SET NULL | SET DEFAULT ] $br
[ON DELETE ] {action} $br
[ON UPDATE ] {action} $br

$br
[-- Deferment configuration ] $br
[ DEFERRABLE | NOT DEFERRABLE ] $br
[ INITIALLY DEFERRED | INITIALLY IMMEDIATE ] $br

$br]]>
    </snippet>

    <snippet id="pk_create" label="Create PRIMARY KEY constraint" object="constraint" parsable="true" placeholders="true">
<![CDATA[[ALTER TABLE IF EXISTS ] {table} $br
[ADD CONSTRAINT ] {name} [ PRIMARY KEY (] {src-columns} ) $br]]>
    </snippet>

    <snippet id="uq_create" label="Create UNIQUE constraint" object="constraint" parsable="true" placeholders="true">
<![CDATA[[ALTER TABLE IF EXISTS ] {table} $br
[ADD CONSTRAINT ] {name} [ UNIQUE (] {src-columns} ) $br]]>
    </snippet>

    <snippet id="conv_create" label="Create conversion" object="conversion" parsable="true" placeholders="true">
<![CDATA[[CREATE ] $ob $sp DEFAULT $sp $cb [ CONVERSION ] {name}
[ FOR  ] {src-encoding} [ TO ] {dst-encoding} [ FROM ] {function} $br]]>
    </snippet>

    <snippet id="db_alterconnlim" label="Alter database connection limit" object="database" parsable="true" placeholders="true">
<![CDATA[[ALTER DATABASE ] {name} [ WITH CONNECTION LIMIT ] {connlimit} $br]]>
    </snippet>

    <snippet id="db_create" label="Create database" object="database" parsable="true" placeholders="true">
<![CDATA[[CREATE DATABASE ] {name} [ WITH] $br
$ob [ OWNER = ] {owner} $sp $cb $br
$ob [ TEMPLATE = ] {template} $sp $cb $br
$ob [ ENCODING = ] {encoding} $sp $cb $br
$ob [ LC_COLLATE = ] {lc-collate} $sp $cb $br
$ob [ LC_CTYPE = ] {lc-ctype} $sp $cb $br
$ob [ TABLESPACE = ] {tablespace} $sp $cb $br
$ob [ CONNECTION LIMIT = ] {connlimit} $sp $cb $br]]>
    </snippet>

    <snippet id="dom_addcheck" label="Add domain's check constraint" object="domain" parsable="true" placeholders="true">
<![CDATA[[ALTER DOMAIN ] {name} [ ADD CONSTRAINT ] {constraint} $br
[CHECK (] {expression} [) ] $ob [ NOT VALID ] $cb  $br]]>
    </snippet>

    <snippet id="dom_create" label="Create domain" object="domain" parsable="true" placeholders="true">
<![CDATA[[CREATE DOMAIN ] {name} [ AS ] {type} $br
$ob [ COLLATE ] {collation} $cb $br
$ob [ DEFAULT ] {default-value} $cb $br
$ob [ CONSTRAINT ] {constraint} $cb $br
$ob [ NOT NULL | NULL | CHECK ] ({expression}) $cb $br]]>
    </snippet>

    <snippet id="dom_dropconstr" label="Drop domain's constraint" object="domain" parsable="true" placeholders="true">
<![CDATA[[ALTER DOMAIN ] {name} [ DROP CONSTRAINT IF EXISTS ] {constraint} $sp $ob [ RESTRICT | CASCADE ] $cb $br]]>
    </snippet>

    <snippet id="dom_dropdefault" label="Drop domain's default value" object="domain" parsable="true" placeholders="true">
<![CDATA[[ALTER DOMAIN ] {name} [ DROP DEFAULT] $br]]>
    </snippet>

    <snippet id="dom_dropnotnull" label="Drop domain's not null constraint" object="domain" parsable="true" placeholders="true">
<![CDATA[[ALTER DOMAIN ] {name} [ DROP NOT NULL] $br]]>
    </snippet>

    <snippet id="dom_renconstr" label="Rename domain's constraint" object="domain" parsable="true" placeholders="true">
<![CDATA[[ALTER DOMAIN ] {name} [ RENAME CONSTRAINT ] {constraint} [ TO ] {new-name} $br]]>
    </snippet>

    <snippet id="dom_setdefault" label="Set domain's default value" object="domain" parsable="true" placeholders="true">
<![CDATA[[ALTER DOMAIN ] {name} [ SET DEFAULT ] {expression} $br]]>
    </snippet>

    <snippet id="dom_setnotnull" label="Set domain's not null constraint" object="domain" parsable="true" placeholders="true">
<![CDATA[[ALTER DOMAIN ] {name} [ SET NOT NULL] $br]]>
    </snippet>

    <snippet id="dom_validconstr" label="Validate domain's constraint" object="domain" parsable="true" placeholders="true">
<![CDATA[[ALTER DOMAIN ] {name} [ VALIDATE CONSTRAINT ] {constraint} $br]]>
    </snippet>

    <snippet id="evnt_create" label="Create event trigger" object="eventtrigger" parsable="true" placeholders="true">
<![CDATA[[CREATE EVENT TRIGGER ] {name} $br
[ ON ] {event} $br
$ob [ WHEN TAG IN (] {values}) $sp $cb $br
[ EXECUTE PROCEDURE ] {function} $br]]>
    </snippet>

    <snippet id="evnt_disable" label="Disable event trigger" object="eventtrigger" parsable="true" placeholders="true">
<![CDATA[[ALTER EVENT TRIGGER ] {name} [ DISABLE] $br]]>
    </snippet>

    <snippet id="evnt_enable" label="Enable event trigger" object="eventtrigger" parsable="true" placeholders="true">
<![CDATA[[ALTER EVENT TRIGGER ] {name} [ ENABLE ] $ob [ REPLICA | ALWAYS ] $cb $br]]>
    </snippet>

    <snippet id="ext_create" label="Create extension" object="extension" parsable="true" placeholders="true">
<![CDATA[[CREATE EXTENSION IF NOT EXISTS ] {name} [ WITH] $br
$ob [ SCHEMA ] {schema} $sp $cb $br
$ob [ VERSION ] '{cur-version}' $sp $cb $br
$ob [ FROM ] '{old-version}' $sp $cb $br]]>
    </snippet>

    <snippet id="ext_update" label="Update extension" object="extension" parsable="true" placeholders="true">
<![CDATA[[ALTER EXTENSION ] {name} [ UPDATE ] $ob [ TO ] $ob $sp '{new-version}' $sp $cb $br]]>
    </snippet>

    <snippet id="fdw_alter" label="Alter foreign data wrapper" object="foreigndatawrapper" parsable="true" placeholders="true">
<![CDATA[[ALTER FOREIGN DATA WRAPPER ] {name} $br
$tb $ob [ HANDLER ] {handler} [ | ] [ NO HANDLER ] $cb $br
$tb $ob [ VALIDATOR ] {validator} [ | ] [ NO VALIDATOR ] $cb $br
$tb $ob [ OPTIONS ( ADD | SET | DROP option 'value' ) ] $cb]]>
    </snippet>

    <snippet id="fdw_create" label="Create foreign data wrapper" object="foreigndatawrapper" parsable="true" placeholders="true">
<![CDATA[[CREATE FOREIGN DATA WRAPPER ] {name} $br
$tb $ob [ HANDLER ] {handler} [ | NO HANDLER ] $cb $br
$tb $ob [ VALIDATOR ] {validator} [ | NO VALIDATOR ] $cb  $br]]>
    </snippet>

    <snippet id="srv_alter" label="Alter foreign server" object="foreignserver" parsable="true" placeholders="true">
<![CDATA[[ ALTER SERVER ] {name} $ob [ VERSION 'new_version' ] $cb $br
$ob [ OPTIONS ( ADD | SET | DROP option 'value' ) ] $cb ]]>
    </snippet>

    <snippet id="srv_create" label="Create foreing server" object="foreignserver" parsable="true" placeholders="true">
<![CDATA[[CREATE SERVER ] $ob [ IF NOT EXISTS ] $cb $sp {name} $ob [ TYPE '{type}' ] $cb $sp $ob [ VERSION '{version}' ] $cb $br
[ FOREIGN DATA WRAPPER ] {fdw} $br
$ob [ OPTIONS ( option 'value' ) ] $cb]]>
    </snippet>

    <snippet id="func_alterbehav" label="Alter a function's behavior" object="function" parsable="true" placeholders="true">
<![CDATA[[ALTER FUNCTION ] {signature} $br
$ob [ CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT ] $cb $br]]>
    </snippet>

    <snippet id="func_altercost" label="Alter a function's execution cost" object="function" parsable="true" placeholders="true">
<![CDATA[[ALTER FUNCTION ] {signature} [ COST ] {execution-cost} $br]]>
    </snippet>

    <snippet id="func_alterrows" label="Alter a function's returned rows amount" object="function" parsable="true" placeholders="true">
<![CDATA[[ALTER FUNCTION ] {signature} [ ROWS ] {row-amount} $br]]>
    </snippet>

    <snippet id="func_altersec" label="Alter a function's security type" object="function" parsable="true" placeholders="true">
<![CDATA[[ALTER FUNCTION ] {signature} $br
$ob [ EXTERNAL ] $cb [ SECURITY ] $ob [ INVOKER | DEFINER ] $cb $br]]>
    </snippet>

    <snippet id="func_altertype" label="Alter a function's type" object="function" parsable="true" placeholders="true">
<![CDATA[[ALTER FUNCTION ] {signature} $br
$ob [ IMMUTABLE | STABLE | VOLATILE ] $cb $br]]>
    </snippet>

    <snippet id="func_c" label="Create a C based function" object="function" parsable="true" placeholders="true">
<![CDATA[[CREATE OR REPLACE FUNCTION ] {name} $sp ({arg-types}) $br
RETURNS $sp {return-type} $br
[AS ] '{library}' [, ] '{definition}' $br
%if ({window}=="true") %then WINDOW $br %end
%if ({leakproof}=="true") %then LEAKPROOF $br %end
{function-type} $br
{behavior-type} $br
{security-type} $br
[COST ] {execution-cost} $br
[ROWS ] {row-amount} $br
[LANGUAGE c] $br]]>
    </snippet>

    <snippet id="func_create" label="Create function" object="function" parsable="true" placeholders="true">
<![CDATA[[CREATE OR REPLACE FUNCTION ] {name} $sp ({arg-types}) $br
-- arg-types: $sp $ob [ IN | OUT | INOUT | VARIADIC ] $cb $sp {arg-name} $sp {arg-type} $sp $ob [ DEFAULT ] $sp {expression} $sp $cb $ob [ , ... ] $cb

$br $br
[-- Function returns a single result or results of the same type ] $br
RETURNS $ob [ SET OF ] $cb $sp {return-type} $br

[-- Function returns a table ] $br
[RETURNS TABLE (] {col-name} $sp {col-type} $ob [, ...] $cb ) $br
$br
[-- Definition for C based function ] $br
[AS ] '{library}' [, ] '{definition}' $br

[-- Definition for SQL or PL/PGSQL based function ] $br
[AS $$] $br
{definition} $br
[$$] $br $br

WINDOW $br
$ob [ NOT ] $cb LEAKPROOF $br
{function-type} [ -- IMMUTABLE | STABLE | VOLATILE ] $br
{behavior-type} [ -- CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT ] $br
{security-type} [ -- ] $ob EXTERNAL $cb $sp SECURITY $ob [ INVOKER | DEFINER ] $cb $br
[COST ] {execution-cost} $br
[ROWS ] {row-amount} $br
[LANGUAGE ] {language} $br]]>
    </snippet>

    <snippet id="func_leakproof" label="Alter a function's leakproof status" object="function" parsable="true" placeholders="true">
<![CDATA[[ALTER FUNCTION ] {signature} $ob [ NOT ] $cb $sp LEAKPROOF $br]]>
    </snippet>

    <snippet id="func_plpgsql" label="Create a PL/PGSQL based function" object="function" parsable="true" placeholders="true">
<![CDATA[[CREATE OR REPLACE FUNCTION ] {name} $sp ({arg-types}) $br
RETURNS $sp {return-type} $br
[AS $$] $br
{definition} $br
[$$] $br
%if ({window}=="true") %then WINDOW $br %end
%if {function-type} %then {function-type} $br %end
%if ({leakproof}=="true") %then LEAKPROOF $br %end
%if {behavior-type} %then {behavior-type} $br %end
%if {security-type} %then  {security-type} $br %end
%if {execution-cost} %then [COST ] {execution-cost} $br %end
%if {row-amount} %then [ROWS ] {row-amount} $br %end
[LANGUAGE plpgsql] $br]]>
    </snippet>

    <snippet id="func_sql" label="Create a SQL based function" object="function" parsable="true" placeholders="true">
<![CDATA[[CREATE OR REPLACE FUNCTION ] {name} $sp ({arg-types}) $br
RETURNS $sp {return-type} $br
[AS $$] $br
{definition} $br
[$$] $br
%if ({window}=="true") %then WINDOW $br %end
%if {function-type} %then {function-type} $br %end
%if ({leakproof}=="true") %then LEAKPROOF $br %end
%if {behavior-type} %then {behavior-type} $br %end
%if {security-type} %then  {security-type} $br %end
%if {execution-cost} %then [COST ] {execution-cost} $br %end
%if {row-amount} %then [ROWS ] {row-amount} $br %end
[LANGUAGE sql] $br]]>
    </snippet>

    <snippet id="idx_create" label="Create index" object="index" parsable="true" placeholders="true">
<![CDATA[[CREATE ] $ob [ UNIQUE ] $cb [ INDEX ] $ob [ CONCURRENTLY ] $cb $sp {name} [ ON ] {table} $br
[USING ] {index-type} $br
( {columns} [) | (] {expressions}) $br $br

[-- All indexes accepts FILLFACTOR value from 10 to 100 (default is 90)] $br
$ob [ WITH ( FILLFACTOR = ] {factor} [ ) ] $cb $br

[-- GiST indexes accepts BUFFERING storage paramenter ] $br
$ob [ WITH ( BUFFERING =  ON | OFF | AUTO ) ] $cb $br

[-- GIN indexes accepts FASTUPDATE storage paramenter ] $br
$ob [ WITH ( FASTUPDATE = ON | OFF ) ] $cb $br

$br
$ob [ TABLESPACE ] {tablespace} $sp $cb  $br
$ob [ WHERE ] {predicate} $sp $cb $br ]]>
    </snippet>

    <snippet id="lang_create" label="Create language" object="language" parsable="true" placeholders="true">
<![CDATA[[CREATE ] $ob [ OR REPLACE ] $cb [ LANGUAGE ] {name} $br]]>
    </snippet>

    <snippet id="lang_createfunc" label="Create language with functions" object="language" parsable="true" placeholders="true">
<![CDATA[[CREATE ] $ob [ OR REPLACE ] $cb $sp $ob [ TRUSTED ] $cb [ LANGUAGE ] {name} $br
[HANDLER ] {handler} $br
$ob [ INLINE ] {inline} $sp $cb $br
$ob [ VALIDATOR ] {validator} $sp $cb $br]]>
    </snippet>

    <snippet id="opr_create" label="Create operator" object="operator" parsable="true" placeholders="true">
<![CDATA[[CREATE OPERATOR ] {name} [ (] $br
[PROCEDURE = ] {function} $br
$ob [, LEFTARG = ] {left-type} $sp $cb $br
$ob [, RIGHTARG = ] {right-type} $sp $cb $br
$ob [, COMMUTATOR = ] {commutator-op} $sp $cb $br
$ob [, NEGATOR = ] {negator-op} $sp $cb $br
$ob [, RESTRICT = ] {restriction} $sp $cb $br
$ob [, JOIN = ] {join} $sp $cb $br
$ob [, HASHES ] $cb $br
$ob [, MERGES ] $cb $br
) $br]]>
    </snippet>

    <snippet id="opc_create" label="Create operator class" object="opclass" parsable="true" placeholders="true">
<![CDATA[[CREATE OPERATOR CLASS ] {name} $ob [ DEFAULT ] $cb [ FOR TYPE ] {type} $br
[USING ] {index-type} $sp $ob [ FAMILY ] {family} $sp $cb [ AS] $br
$br
[-- Create an OPERATOR element ] $br
[OPERATOR ] {stg-number} $sp {operator} $sp $ob [ FOR SEARCH | FOR ORDER BY ] $cb $sp {sort-family}
$br
[-- Create a FUNCTION element ] $br
[FUNCTION ] $sp {supp-number} $sp {function}
$br
[-- Create a STORAGE element ] $br
[STORAGE ] {type} $br]]>
    </snippet>

    <snippet id="opf_create" label="Create operator family" object="opfamily" parsable="true" placeholders="true">
<![CDATA[[CREATE OPERATOR FAMILY ] {name} [ USING ] {index-type} $br]]>
    </snippet>

    <snippet id="pol_alter" label="Alter policy" object="policy" parsable="true" placeholders="true">
<![CDATA[[ALTER POLICY ] {name} [ ON ] {table}
$br $tb [TO ] {roles}
$br $tb [USING (] {using-exp} [)]
$br $tb [WITH CHECK (] {check-exp} [)] ; $br]]>
    </snippet>

    <snippet id="pol_create" label="Create policy" object="policy" parsable="true" placeholders="true">
<![CDATA[[CREATE POLICY ] {name} [ ON ] {table}
$br $tb [AS { PERMISSIVE | RESTRICTIVE } -- Only in PostgreSQL 10+ ]
$br $tb [FOR ] {command}
$br $tb [TO ] {roles}
$br $tb [USING (] {using-exp} [)]
$br $tb [WITH CHECK (] {check-exp} [)];$br]]>
    </snippet>

    <snippet id="rol_alter" label="Alter role attributes" object="role" parsable="true" placeholders="true">
<![CDATA[%set {no-mod} NO
[ALTER ROLE ] {name} [ WITH ] $br

%if ({superuser}=="false") %then {no-mod} %end SUPERUSER $br
%if ({createdb}=="false") %then {no-mod} %end CREATEDB $br
%if ({createrole}=="false") %then {no-mod} %end CREATEROLE $br
%if ({inherit}=="false") %then {no-mod} %end INHERIT $br
%if ({login}=="false") %then {no-mod} %end LOGIN $br
%if ({replication}=="false") %then {no-mod} %end REPLICATION $br

[CONNECTION LIMIT ] {connlimit} $br
$ob [ ENCRYPTED | UNENCRYPTED ] $cb [ PASSWORD ] '{new-password}' $br
[VALID UNTIL ] '{validity}' $br]]>
    </snippet>

    <snippet id="rol_clone" label="Clone role" object="role" parsable="true" placeholders="false">
<![CDATA[[CREATE ROLE ] {name} [ WITH ] $br
%if ({superuser}=="true") %then SUPERUSER $br %end
%if ({createdb}=="true") %then CREATEDB $br %end
%if ({createrole}=="true") %then CREATEROLE $br %end
%if ({inherit}=="true") %then INHERIT $br %end
%if ({login}=="true") %then LOGIN $br %end
%if ({replication}=="true") %then REPLICATION $br %end
%if {connlimit} %then [CONNECTION LIMIT ] {connlimit} $br %end
%if ({encrypted}=="true") %then ENCRYPTED %else UNENCRYPTED %end
[ PASSWORD ] '{password}' $br

%if {validity} %then [VALID UNTIL ] '{validity}' $br %end
%if {ref-roles} %then [IN ROLE ] {ref-roles} $br %end
%if {member-roles} %then [ROLE ] {member-roles} $br %end
%if {admin-roles} %then [ADMIN ] {admin-roles} $br %end
$br]]>
    </snippet>

    <snippet id="rol_create" label="Create role" object="role" parsable="true" placeholders="true">
<![CDATA[[CREATE ROLE ] {name} [ WITH ] $br
SUPERUSER $br
CREATEDB $br
CREATEROLE $br
INHERIT $br
LOGIN $br
REPLICATION $br
[CONNECTION LIMIT ] {connlimit} $br
$ob [ ENCRYPTED | UNENCRYPTED ] $cb [ PASSWORD ] '{password}' $br
[VALID UNTIL ] '{validity}' $br
[IN ROLE ] {ref-roles} $br
[ROLE ] {member-roles} $br
[ADMIN ] {admin-roles} $br]]>
    </snippet>

    <snippet id="rule_create" label="Create rule" object="rule" parsable="true" placeholders="true">
<![CDATA[[CREATE ] $ob [ OR REPLACE ] $cb [ RULE ] {name} [ AS] $br
[ON ] {event-type} [ -- event-type: SELECT | INSERT | UPDATE | DELETE ] $br
[TO ] {table} $br
$ob [ WHERE ] {condition} $sp $cb $br
[DO ] {exec-type} [ -- exec-type: ALSO | INSTEAD ] $br
$br
[-- commands: NOTHING | command | (command; command; ...) ] $br
({commands}) $br]]>
    </snippet>

    <snippet id="sch_create" label="Create schema" object="schema" parsable="true" placeholders="true">
<![CDATA[[CREATE SCHEMA ] {name} $br]]>
    </snippet>

    <snippet id="seq_alter" label="Alter sequence" object="sequence" parsable="true" placeholders="true">
<![CDATA[[ALTER SEQUENCE ] {name} $br
[RESTART ] {restart} $br
[INCREMENT ] {increment} $br
[MINVALUE ] {min-value} $br
[MAXVALUE ] {max-value} $br
[START ] {start} $br
[CACHE ] {cache} $br
%if ({cycle}=="false") %then [NO ] %end CYCLE $br
[OWNED BY ] %if {owner-col} %then {owner-col} %else [ NONE] %end
$br]]>
    </snippet>

    <snippet id="seq_clone" label="Clone sequence" object="sequence" parsable="true" placeholders="false">
<![CDATA[[CREATE SEQUENCE ] {name} $br
[INCREMENT ] {increment} $br
[MINVALUE ] {min-value} $br
[MAXVALUE ] {max-value} $br
[START ] {start} $br
[CACHE ] {cache} $br
%if ({cycle}=="false") %then [NO ] %end CYCLE $br
[OWNED BY ] %if {owner-col} %then {owner-col} %else [ NONE] %end
$br]]>
    </snippet>

    <snippet id="seq_create" label="Create sequence" object="sequence" parsable="true" placeholders="true">
<![CDATA[[CREATE ] $ob [ TEMPORARY | TEMP ] $cb [ SEQUENCE ] {name} $br
$ob [ INCREMENT ] {increment} $sp $cb $br
$ob [ MINVALUE ] $ob $sp {min-value} [ | NO MINVALUE ] $cb $sp $cb $br
$ob [ MAXVALUE ] $ob $sp {max-value} [ | NO MAXVALUE ] $cb $sp $cb $br
$ob [ START ] {start} $sp $cb $br
$ob [ CACHE ] {cache} $sp $cb $br
$ob $sp $ob [ NO ] $cb [ CYCLE ] $sp $cb $br
$ob [ OWNED BY ] $ob $sp {owner-col} [ | NONE ] $cb $sp $cb $br]]>
    </snippet>

    <snippet id="select_first_500" label="Select first 500 rows" object="table" parsable="true" placeholders="true">
<![CDATA[[SELECT * FROM ] {name} [ LIMIT 500;]]]>
    </snippet>

    <snippet id="tab_create" label="Create table" object="table" parsable="true" placeholders="true">
<![CDATA[[CREATE ] $ob [ TEMPORARY | UNLOGGED ] $cb [ TABLE IF NOT EXISTS ] {name} [ (] $br
[   ] {col-name} $sp {type} $sp $ob [ COLLATE ] {collation} $sp $cb , $br
[   ] {constraints} $br
[)] $br
$ob $sp $ob [ WITH | WITHOUT ] $cb [ OIDS ] $cb $br
$ob [ TABLESPACE ] {tablespace} $sp $cb $br]]>
    </snippet>

    <snippet id="tab_idcolumn" label="Create a table with a single ID column of type 'serial'" object="table" parsable="true" placeholders="true">
<![CDATA[[CREATE TABLE IF NOT EXISTS ] {new-name} [ (] $br
[    id serial,] $br
[    CONSTRAINT ] {new-name}_pk [ PRIMARY KEY(id)] $br
[)] $br
$ob [ TABLESPACE ] {tablespace} $sp $cb $br]]>
    </snippet>

    <snippet id="tab_inherit" label="Create inherited table" object="table" parsable="true" placeholders="true">
<![CDATA[[CREATE TABLE IF NOT EXISTS ] {new-name} [ (] $br
[)] $br
[INHERITS ] {name} [ -- name: comma separated list of tables ] $br
$ob [ TABLESPACE ] {tablespace} $sp $cb $br]]>
    </snippet>

    <snippet id="tab_like" label="Create a dettached table (LIKE)" object="table" parsable="true" placeholders="true">
<![CDATA[[CREATE TABLE IF NOT EXISTS ] {new-name} [ (] $br
[   LIKE ] {name} $sp $ob $sp $ob [ INCLUDING | EXCLUDING ] $cb $sp $ob [ DEFAULTS | CONSTRAINTS | INDEXES | STORAGE | COMMENTS | ALL ] $cb $sp $cb $br
[)] $br
$ob [ TABLESPACE ] {tablespace} $sp $cb $br]]>
    </snippet>

    <snippet id="tbs_create" label="Create tablespace" object="tablespace" parsable="true" placeholders="true">
<![CDATA[[CREATE TABLESPACE ] {name} $br
$ob [ OWNER ] {owner} $sp $cb $br
[LOCATION ] '{directory}' $br]]>
    </snippet>

    <snippet id="trg_clone" label="Clone trigger" object="trigger" parsable="true" placeholders="false">
<![CDATA[[CREATE ]

%if ({constraint}=="true")  %then
 [ CONSTRAINT ]
%end

[ TRIGGER ] {name} $br

{firing-type}

%if ({ins-event}=="true") %then
  %set {event} [ INSERT ]
%end

%if ({del-event}=="true") %then
  %if {event} %then
     %set {event} {event} [ OR]
  %end
  %set {event} {event} [ DELETE ]
%end

%if ({trunc-event}=="true") %then
  %if {event} %then
    %set {event} {event} [ OR]
  %end
  %set {event} {event} [ TRUNCATE ]
%end

%if ({upd-event}=="true") %then
  %if {event} %then
     %set {event} {event} [ OR]
  %end

  %set {event} {event} [ UPDATE ]

  %if {columns} %then
    %set {event} {event} [OF ] {columns}
  %end
%end

{event} $br

[ON ] {table} $br

%if ({constraint}=="true") %then
  [FROM ] {ref-table} $br

  %if ({deferrable}=="true") %then
    [ DEFERRABLE ] {defer-type} $br
  %else
    [NOT DEFERRABLE ] $br
  %end
%end

[FOR EACH ]
%if ({per-line}=="true") %then
  ROW
%else
  STATEMENT
%end

$br
%if {condition} %then
 [WHEN ] ({condition}) $br
%end

[EXECUTE PROCEDURE ] {trigger-func} $br
]]>
    </snippet>

    <snippet id="trg_create" label="Create trigger" object="trigger" parsable="true" placeholders="true">
<![CDATA[[CREATE ] $ob [ CONSTRAINT ] $cb [ TRIGGER ] {name} $br
{firing-type} [ -- BEFORE | AFTER | INSTEAD OF ] $br
{events} [ -- INSERT | DELETE | TRUNCATE | UPDATE ] $ob $sp [ OF {column} ] $ob [, ... ] $cb $sp $cb $br
[ON ] {table} $br
$br
[-- Constraint trigger attributes ] $br
$ob [ FROM ] {ref-table} $sp $cb $br
$ob [ NOT DEFERRABLE | DEFERRABLE ] $cb $sp $ob [ INITIALLY IMMEDIATE | INITIALLY DEFERRED ] $cb $br
$br
$ob [ FOR ] $ob [ EACH ] $cb $sp $ob [ ROW | STATEMENT ] $cb $sp $cb $br
$ob [ WHEN ] ({condition}) $sp $cb $br
[EXECUTE PROCEDURE ] {trigger-func} $br]]>
    </snippet>

    <snippet id="type_addattr" label="Add attribute to composite type" object="usertype" parsable="true" placeholders="true">
<![CDATA[[ALTER TYPE ] {name} [ ADD ATTRIBUTE ] {attr-name} $sp {type} $sp $ob [ COLLATE ] $sp {collation} $sp $cb $sp $ob [ CASCADE | RESTRICT ] $cb $br]]>
    </snippet>

    <snippet id="type_addenum" label="Add element to enumeration type" object="usertype" parsable="true" placeholders="true">
<![CDATA[[ALTER TYPE ] {name} [ ADD VALUE IF NOT EXISTS ] {enum} $sp $ob [ BEFORE | AFTER ] {existing-enum} $sp $cb $br]]>
    </snippet>

    <snippet id="type_alterattr" label="Change composite type attribute data type" object="usertype" parsable="true" placeholders="true">
<![CDATA[[ALTER TYPE ] {name} [ ALTER ATTRIBUTE ] {attr-name} [ TYPE ] {type} $sp $ob [ COLLATE ] $sp {collation} $sp $cb $sp $ob [ CASCADE | RESTRICT ] $cb $br]]>
    </snippet>

    <snippet id="type_base" label="Create base type" object="usertype" parsable="true" placeholders="true">
<![CDATA[[CREATE TYPE ] {name} [ (] $br
[INPUT = ] {input}, $br
[OUTPUT = ] {output} $br
$ob [ , RECEIVE = ] {receive} $sp $cb $br
$ob [ , SEND = ] {send}  $sp $cb $br
$ob [ , TYPMOD_IN = ] {tpmodin} $sp $cb $br
$ob [ , TYPMOD_OUT = ] {tpmodout} $sp $cb $br
$ob [ , ANALYZE = ] {analyze} $sp $cb $br
$ob [ , INTERNALLENGTH = ] $ob {internal-length} | VARIABLE  $sp $cb $br
$ob [ , PASSEDBYVALUE ] $cb $br

$ob [ , ALIGNMENT = ] {alignment} $sp $cb
[ -- integer | char | smallint | double precision ]$br

$ob [ , STORAGE = ] {storage} $sp $cb
[ -- plain | extended | external | main ]$br

$ob [ , LIKE = ] {like-type} $sp $cb
[ -- Type in which attributes will be copied ]$br

$ob [ , CATEGORY = ] '{category}' $sp $cb $br
$ob [ , PREFERRED = TRUE | FALSE ] $sp $cb $br
$ob [ , DEFAULT = ] {default-value}  $sp $cb $br

$ob [ , ELEMENT = ] {element} $sp $cb
[ -- Type of elements when the type is array ]$br

$ob [ , DELIMITER = ] '{delimiter}' $sp $cb
[ -- Value delimiter when the type is array ]$br

$ob [ , COLLATABLE = TRUE | FALSE ] $cb $br
) $br]]>
    </snippet>

    <snippet id="type_comp" label="Create composite type" object="usertype" parsable="true" placeholders="true">
<![CDATA[[CREATE TYPE ] {name} [ AS (] $br
[    ] {attr-name} $sp {type} $sp $ob [ COLLATE ] {collation} $sp $cb $sp $ob [, ... ] $cb $sp $br
) $br]]>
    </snippet>

    <snippet id="type_dropattr" label="Drop attribute from composite type" object="usertype" parsable="true" placeholders="true">
<![CDATA[[ALTER TYPE ] {name} [ DROP ATTRIBUTE IF EXISTS ] {attr-name} $sp $ob [ CASCADE | RESTRICT ] $cb $br]]>
    </snippet>

    <snippet id="type_enum" label="Create enumeration type" object="usertype" parsable="true" placeholders="true">
<![CDATA[[CREATE TYPE ] {name} [ AS ENUM ]
[( ] [ '{label}' ] $ob [, ... ] $cb $sp [ )] $br]]>
    </snippet>

    <snippet id="type_range" label="Create range type" object="usertype" parsable="true" placeholders="true">
<![CDATA[[CREATE TYPE ] {name} [ AS RANGE (] $br
[SUBTYPE = ] {subtype} $br
$ob [ , SUBTYPE_OPCLASS = ] {opclass} $sp $cb $br
$ob [ , COLLATION = ] {collation} $sp $cb $br
$ob [ , CANONICAL = ] {canonical} $sp $cb $br
$ob [ , SUBTYPE_DIFF = ] {subtypediff} $sp $cb $br
) $br]]>
    </snippet>

    <snippet id="type_renattr" label="Rename composite type attribute" object="usertype" parsable="true" placeholders="true">
<![CDATA[[ALTER TYPE ] {name} [ RENAME ATTRIBUTE ] {attribute} [ TO ] {new-name} $sp $ob [ CASCADE | RESTRICT ] $cb $br]]>
    </snippet>

    <snippet id="select_first_500v" label="Select first 500 rows" object="view" parsable="true" placeholders="true">
<![CDATA[[SELECT * FROM ] {name} [ LIMIT 500;]]]>
    </snippet>

    <snippet id="view_create" label="Create view" object="view" parsable="true" placeholders="true">
<![CDATA[[CREATE ] $ob [ OR REPLACE ]$cb $sp $ob [ TEMPORARY ] $cb $sp $ob [ RECURSIVE ] $cb [ VIEW ] {name} $br
[AS ] {definition} $br]]>
    </snippet>

    <snippet id="view_materialized" label="Create materialized view" object="view" parsable="true" placeholders="true">
<![CDATA[[CREATE MATERIALIZED VIEW ] {name} $br
$ob [ TABLESPACE ] {tablespace} $sp $cb $br
[AS ] {definition} $br]]>
    </snippet>

</snippets>
