All Downloads are FREE. Search and download functionalities are using the official Maven repository.

template.component.table.default.create.ftl Maven / Gradle / Ivy

<#--
  ~ Licensed to the Apache Software Foundation (ASF) under one or more
  ~ contributor license agreements.  See the NOTICE file distributed with
  ~ this work for additional information regarding copyright ownership.
  ~ The ASF licenses this file to You under the Apache License, Version 2.0
  ~ (the "License"); you may not use this file except in compliance with
  ~ the License.  You may obtain a copy of the License at
  ~
  ~     http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<#import "../../../macro/constraints.ftl" as CONSTRAINTS>
CREATE <#if relpersistence!false >UNLOGGED TABLE IF NOT EXISTS ${schema}.${name}
<#if typname?? >
OF ${typname }

<#if like_relation?? || coll_inherits?size gt 0 || columns?size gt 0 || primary_key?size gt 0 || unique_constraint?size gt 0 || foreign_key?size gt 0 || check_constraint?size gt 0 || exclude_constraint?size gt 0 >
(

<#if like_relation?? >
LIKE ${like_relation }<#if like_default_value!false >
INCLUDING DEFAULTS<#if like_constraints!false >
INCLUDING CONSTRAINTS<#if like_indexes!false >
INCLUDING INDEXES<#if like_storage!false >
INCLUDING STORAGE<#if  like_comments!false >
INCLUDING COMMENTS<#if  columns?size gt 0 >,


<#if columns?? && columns?size gt 0 >
<#list columns as c >
<#if c.name?? && c.cltype?? >
<#if c.inheritedfromtable?? >-- Inherited from table ${c.inheritedfromtable}: <#elseif c.inheritedfromtype?? >-- Inherited from type ${c.inheritedfromtype}: ${c.name} ${c.displaytypname}<#if c.collspcname?? && c.collspcname?length gt 0 > COLLATE ${c.collspcname}<#if c.attnotnull!false > NOT NULL<#if c.defval?? && c.defval != ''> DEFAULT ${c.defval}
<#if c.colconstype?? && c.colconstype == 'i' && c.attidentity?? && c.attidentity != '' >
<#if c.attidentity?? &&  c.attidentity == 'a' > GENERATED ALWAYS AS IDENTITY<#elseif c.attidentity?? && c.attidentity == 'd' > GENERATED BY DEFAULT AS IDENTITY
<#if c.seqincrement?? || c.seqcycle!false || c.seqincrement?? || c.seqstart?? || c.seqmin?? || c.seqmax?? || c.seqcache?? > ( 
<#if c.seqcycle!false >
CYCLE <#if c.seqincrement?? && c.seqincrement?number gt -1 >
INCREMENT ${c.seqincrement} <#if c.seqstart?? && c.seqstart?number gt -1>
START ${c.seqstart} <#if c.seqmin?? && c.seqmin?number gt -1>
MINVALUE ${c.seqmin} <#if c.seqmax?? && c.seqmax?number gt -1>
MAXVALUE ${c.seqmax} <#if c.seqcache?? && c.seqcache?number gt -1>
CACHE ${c.seqcache} 
<#if c.seqincrement?? || c.seqcycle!false || c.seqincrement?? || c.seqstart?? || c.seqmin?? || c.seqmax?? || c.seqcache?? >)

<#if c?counter lt columns?size>,




<#if primary_key?size gt 0 ><#if columns?size gt 0 >,
<@CONSTRAINTS.PRIMARY_KEY data=primary_key[0] /><#if unique_constraint?size gt 0 ><#if columns?size gt 0 || primary_key?size gt 0 >,
<@CONSTRAINTS.UNIQUE unique_data=unique_constraint /><#if foreign_key?size gt 0 ><#if columns?size gt 0 || primary_key?size gt 0 || unique_constraint?size gt 0 >,
<@CONSTRAINTS.FOREIGN_KEY foreign_key_data=foreign_key /><#if check_constraint?size gt 0 ><#if columns?size gt 0 || primary_key?size gt 0 || unique_constraint?size gt 0 || foreign_key?size gt 0 >,
<@CONSTRAINTS.CHECK check_data=check_constraint/><#if exclude_constraint?size gt 0 ><#if columns?size gt 0 || primary_key?size gt 0 || unique_constraint?size gt 0 || foreign_key?size gt 0 || check_constraint?size gt 0 >,
<@CONSTRAINTS.EXCLUDE exclude_data=exclude_constraint/>
<#if like_relation?? || coll_inherits?size gt 0 || columns?size gt 0 || primary_key?size gt 0 || unique_constraint?size gt 0 || foreign_key?size gt 0 || check_constraint?size gt 0 || exclude_constraint?size gt 0 >
)<#if relkind?? && relkind == 'p' > PARTITION BY ${ partition_scheme }
<#if coll_inherits?? && coll_inherits?size gt 0>
INHERITS (<#list coll_inherits as val ><#if val?counter != 1 >, ${val})

WITH (
OIDS = <#if relhasoids!false >TRUE<#else>FALSE<#if fillfactor?? >,
FILLFACTOR = ${ fillfactor }<#if parallel_workers?? && parallel_workers != '' >,
autovacuum_enabled = <#if autovacuum_enabled == 't' >TRUE<#else >FALSE<#if toast_autovacuum_enabled?? && (toast_autovacuum_enabled == 't' || toast_autovacuum_enabled == 'f')  >,
toast.autovacuum_enabled = <#if toast_autovacuum_enabled == 't' >TRUE<#else >FALSE
<#if autovacuum_custom!false && vacuum_table?size gt 0 >
<#list vacuum_table as opt ><#if opt.name?? && opt.value?? >
,
${opt.name} = ${opt.value}
<#if toast_autovacuum!false && vacuum_toast?size gt 0 >
<#list vacuum_toast as opt ><#if opt.name?? && opt.value?? >
,
toast.${opt.name} = ${opt.value}

<#if spcname?? >
)
TABLESPACE ${spcname };
<#else>
);

<#if description?? >
COMMENT ON TABLE ${schema}.${name}
IS '${description}';

<#if columns?? && columns?size gt 0 >
<#list columns as c >
<#if c.description?? >
COMMENT ON COLUMN ${schema}.${name}.${c.name}
IS '${c.description}';



<@CONSTRAINTS.CONSTRAINT_COMMENTS schema=schema table=name data=primary_key/>
<@CONSTRAINTS.CONSTRAINT_COMMENTS schema=schema table=name data=unique_constraint/>
<@CONSTRAINTS.CONSTRAINT_COMMENTS schema=schema table=name data=foreign_key/>
<@CONSTRAINTS.CONSTRAINT_COMMENTS schema=schema table=name data=check_constraint/>
<@CONSTRAINTS.CONSTRAINT_COMMENTS schema=schema table=name data=exclude_constraint/>




© 2015 - 2025 Weber Informatics LLC | Privacy Policy