summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--db/postgresql/datatypes.xml4
-rw-r--r--db/postgresql/output.xsl65
2 files changed, 50 insertions, 19 deletions
diff --git a/db/postgresql/datatypes.xml b/db/postgresql/datatypes.xml
index 7d7f4a3..e493838 100644
--- a/db/postgresql/datatypes.xml
+++ b/db/postgresql/datatypes.xml
@@ -23,10 +23,10 @@
<group label="Date &amp; Time" color="rgb(200,255,200)">
<type label="Date" length="0" sql="DATE" quote="'" />
<type label="Time" length="1" sql="TIME" quote="'" />
- <type label="Time w/ TZ" length="0" sql="TIME WITH TIMEZONE" quote="'" />
+ <type label="Time w/ TZ" length="0" sql="TIME WITH TIME ZONE" quote="'" />
<type label="Interval" length="1" sql="INTERVAL" quote="'" />
<type label="Timestamp" length="1" sql="TIMESTAMP" quote="'" />
- <type label="Timestamp w/ TZ" length="0" sql="TIMESTAMP WITH TIMEZONE" quote="'" />
+ <type label="Timestamp w/ TZ" length="0" sql="TIMESTAMP WITH TIME ZONE" quote="'" />
<type label="Timestamp wo/ TZ" length="0" sql="TIMESTAMP WITHOUT TIME ZONE" quote="'" />
</group>
diff --git a/db/postgresql/output.xsl b/db/postgresql/output.xsl
index a1ff348..2e80dfa 100644
--- a/db/postgresql/output.xsl
+++ b/db/postgresql/output.xsl
@@ -35,7 +35,20 @@
<xsl:value-of select="@name" />
<xsl:text>" </xsl:text>
- <xsl:value-of select="datatype" />
+ <xsl:choose>
+ <xsl:when test="@autoincrement = 1">
+ <!-- use postgresql SERIAL shortcut for columns marked as
+ auto-increment. this creates integer column,
+ corresponding sequence, and default expression for the
+ column with nextval(). see:
+ http://www.postgresql.org/docs/current/static/datatype-numeric.html#DATATYPE-SERIAL
+ -->
+ <xsl:text> SERIAL</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="datatype" />
+ </xsl:otherwise>
+ </xsl:choose>
<xsl:text> </xsl:text>
<xsl:if test="@null = 0">
@@ -43,19 +56,17 @@
</xsl:if>
<xsl:if test="default">
- <xsl:text>DEFAULT </xsl:text>
- <xsl:value-of select="default" />
- <xsl:text> </xsl:text>
+ <xsl:if test=" default != 'NULL' and default != NULL ">
+ <xsl:text>DEFAULT </xsl:text>
+ <xsl:value-of select="default" />
+ <xsl:text> </xsl:text>
+ </xsl:if>
</xsl:if>
<xsl:if test="comment">
- <xsl:text>/* COMMENT '</xsl:text>
- <xsl:call-template name="replace-substring">
- <xsl:with-param name="value" select="comment" />
- <xsl:with-param name="from" select='"&apos;"' />
- <xsl:with-param name="to" select='"&apos;&apos;"' />
- </xsl:call-template>
- <xsl:text>' */</xsl:text>
+ <xsl:text>/* </xsl:text>
+ <xsl:value-of select="comment"/>
+ <xsl:text> */</xsl:text>
</xsl:if>
<xsl:if test="not (position()=last())">
@@ -85,22 +96,42 @@
</xsl:for-each>
<xsl:text>
-)</xsl:text>
+);
+</xsl:text>
<xsl:if test="comment">
- <xsl:text> /* </xsl:text>
- <xsl:call-template name="replace-substring">
+ <xsl:text>COMMENT ON TABLE "</xsl:text>
+ <xsl:value-of select="@name"/>
+ <xsl:text>" IS '</xsl:text>
+ <xsl:call-template name="replace-substring">
<xsl:with-param name="value" select="comment" />
<xsl:with-param name="from" select='"&apos;"' />
<xsl:with-param name="to" select='"&apos;&apos;"' />
</xsl:call-template>
- <xsl:text>*/</xsl:text>
+ <xsl:text>';
+</xsl:text>
</xsl:if>
- <xsl:text>;
-
+<!-- column comments -->
+ <xsl:for-each select="row">
+ <xsl:if test="comment">
+ <xsl:text>COMMENT ON COLUMN "</xsl:text>
+ <xsl:value-of select="../@name"/>
+ <xsl:text>"."</xsl:text>
+ <xsl:value-of select="@name"/>
+ <xsl:text>" IS '</xsl:text>
+ <xsl:call-template name="replace-substring">
+ <xsl:with-param name="value" select="comment" />
+ <xsl:with-param name="from" select='"&apos;"' />
+ <xsl:with-param name="to" select='"&apos;&apos;"' />
+ </xsl:call-template>
+ <xsl:text>';
</xsl:text>
+ </xsl:if>
+ </xsl:for-each>
+ <xsl:text>
+</xsl:text>
</xsl:for-each>
<!-- fk -->