Supported C data types v16

An ECPGPlus application must deal with two sets of data types: SQL data types (such as SMALLINT, DOUBLE PRECISION, and CHARACTER VARYING) and C data types (like short, double, and varchar[n]). When an application fetches data from the server, ECPGPlus maps each SQL data type to the type of the C variable into which the data is returned.

In general, ECPGPlus can convert most SQL server types into similar C types, but not all combinations are valid. For example, ECPGPlus tries to convert a SQL character value into a C integer value, but the conversion might fail at execution time if the SQL character value contains non-numeric characters.

The reverse is also true. When an application sends a value to the server, ECPGPlus tries to convert the C data type into the required SQL type. Again, the conversion might fail at execution time if the C value can't be converted into the required SQL type.

ECPGPlus can convert any SQL type into C character values (char[n] or varchar[n]). Although it's safe to convert any SQL type to or from char[n] or varchar[n], it's often convenient to use more natural C types such as int, double, or float.

The supported C data types are:

  • short
  • int
  • unsigned int
  • long long int
  • float
  • double
  • char[n+1]
  • varchar[n+1]
  • bool
  • Any equivalent created by a typedef

In addition to the numeric and character types supported by C, the pgtypeslib runtime library offers custom data types, as well as functions to operate on those types, for dealing with date/time and exact numeric values:

  • timestamp
  • interval
  • date
  • decimal
  • numeric

To use a data type supplied by pgtypeslib, you must #include the proper header file.