Help Center/ GaussDB/ Developer Guide(Distributed_V2.0-8.x)/ Application Development Guide/ ECPG-based Development/ Running SQL Commands/ Embedded SQL Commands/ TYPE
Updated on 2025-08-19 GMT+08:00
TYPE
Function
Defines a new data type. This command is identified only when ecpg is run with the -c option.
Syntax
TYPE type_name IS ctype
Parameter Description
type_name
Data type name
ctype
C type description.
Example
EXEC SQL TYPE customer IS
struct
{
varchar name[50];
int phone;
};
EXEC SQL TYPE cust_ind IS
struct ind
{
short name_ind;
short phone_ind;
};
EXEC SQL TYPE c IS char reference;
EXEC SQL TYPE ind IS union { int integer; short smallint; };
EXEC SQL TYPE intarray IS int[AMOUNT];
EXEC SQL TYPE str IS varchar[BUFFERSIZ];
EXEC SQL TYPE string IS char[11]; Example of using EXEC SQL TYPE (note that the -c parameter needs to be added in the ecpg preprocessing phase when the following example is used):
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
EXEC SQL WHENEVER SQLERROR SQLPRINT;
EXEC SQL TYPE tt IS
struct
{
varchar v[256];
int i;
};
EXEC SQL TYPE tt_ind IS
struct ind {
short v_ind;
short i_ind;
};
int main(void)
{
EXEC SQL BEGIN DECLARE SECTION;
tt t;
tt_ind t_ind;
EXEC SQL END DECLARE SECTION;
EXEC SQL CONNECT TO testdb AS con1;
EXEC SQL SELECT current_database(), 256 INTO :t:t_ind LIMIT 1;
printf("t.v = %s\n", t.v.arr);
printf("t.i = %d\n", t.i);
printf("t_ind.v_ind = %d\n", t_ind.v_ind);
printf("t_ind.i_ind = %d\n", t_ind.i_ind);
EXEC SQL DISCONNECT con1;
return 0;
} The output of this example is as follows:
t.v = testdb t.i = 256 t_ind.v_ind = 0 t_ind.i_ind = 0
Parent topic: Embedded SQL Commands
What is your overall rating for this page?
0
1
2
3
4
5
6
7
8
9
10
Very dissatisfiedVery satisfied
Thank you very much for your feedback. We will continue working to improve the documentation.
The system is busy. Please try again later.