summaryrefslogtreecommitdiff
path: root/doc/src
diff options
context:
space:
mode:
Diffstat (limited to 'doc/src')
-rw-r--r--doc/src/sgml/ecpg.sgml39
1 files changed, 38 insertions, 1 deletions
diff --git a/doc/src/sgml/ecpg.sgml b/doc/src/sgml/ecpg.sgml
index 7f8b4dd5c02..29333e37679 100644
--- a/doc/src/sgml/ecpg.sgml
+++ b/doc/src/sgml/ecpg.sgml
@@ -1483,6 +1483,10 @@ EXEC SQL END DECLARE SECTION;
<sect4>
<title>Typedefs</title>
+ <indexterm>
+ <primary>typedef</primary>
+ <secondary>in ECPG</secondary>
+ </indexterm>
<para>
Use the <literal>typedef</literal> keyword to map new types to already
@@ -1497,8 +1501,41 @@ EXEC SQL END DECLARE SECTION;
<programlisting>
EXEC SQL TYPE serial_t IS long;
</programlisting>
- This declaration does not need to be part of a declare section.
+ This declaration does not need to be part of a declare section;
+ that is, you can also write typedefs as normal C statements.
</para>
+
+ <para>
+ Any word you declare as a typedef cannot be used as a SQL keyword
+ in <literal>EXEC SQL</literal> commands later in the same program.
+ For example, this won't work:
+<programlisting>
+EXEC SQL BEGIN DECLARE SECTION;
+ typedef int start;
+EXEC SQL END DECLARE SECTION;
+...
+EXEC SQL START TRANSACTION;
+</programlisting>
+ ECPG will report a syntax error for <literal>START
+ TRANSACTION</literal>, because it no longer
+ recognizes <literal>START</literal> as a SQL keyword,
+ only as a typedef.
+ (If you have such a conflict, and renaming the typedef
+ seems impractical, you could write the SQL command
+ using <link linkend="ecpg-dynamic">dynamic SQL</link>.)
+ </para>
+
+ <note>
+ <para>
+ In <productname>PostgreSQL</productname> releases before v16, use
+ of SQL keywords as typedef names was likely to result in syntax
+ errors associated with use of the typedef itself, rather than use
+ of the name as a SQL keyword. The new behavior is less likely to
+ cause problems when an existing ECPG application is recompiled in
+ a new <productname>PostgreSQL</productname> release with new
+ keywords.
+ </para>
+ </note>
</sect4>
<sect4>