Movatterモバイル変換


[0]ホーム

URL:



Facebook
Postgres Pro
Facebook
Downloads
TYPE
Prev Up35.14. Embedded SQL CommandsHome Next

TYPE

TYPE — define a new data type

Synopsis

TYPEtype_name ISctype

Description

TheTYPE command defines a new C type. It is equivalent to putting atypedef into a declare section.

This command is only recognized whenecpg is run with the-c option.

Parameters

type_name

The name for the new type. It must be a valid C type name.

ctype

A C type specification.

Examples

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];

Here is an example program that usesEXEC SQL TYPE:

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;    };intmain(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 pg_catalog.set_config('search_path', '', false); EXEC SQL COMMIT;    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 from this program looks like this:

t.v = testdbt.i = 256t_ind.v_ind = 0t_ind.i_ind = 0

Compatibility

TheTYPE command is a PostgreSQL extension.


Prev Up Next
SET DESCRIPTOR Home VAR
epubpdf
Go to PostgreSQL 10
By continuing to browse this website, you agree to the use of cookies. Go toPrivacy Policy.

[8]ページ先頭

©2009-2025 Movatter.jp