All Products
Search
Document Center

AnalyticDB for PostgreSQL:Create a vector table

Last Updated:Sep 06, 2023

This topic describes how to create a vector table. The used syntax is fully compatible with SQL:1999 and partially compatible with SQL:2003.

Prerequisites

Vector search engine optimization is enabled. For more information, see Enable or disable vector search engine optimization.

Syntax

The syntax for creating a vector table is the same as the syntax for creating a heap table in AnalyticDB for PostgreSQL. The vector column (VECTORTYPE) in the table is represented by an array and supports the following types: SMALLINT[], FLOAT2[], and REAL(FLOAT4)[]. A table supports multiple vector columns.

CREATE TABLE [TABLE_NAME]
(  
    C1 DATATYPE,  
    C2 DATATYPE,  
    ......,  
    CN VECTORTYPE, 
    PRIMARY KEY (one or more columns)
) DISTRIBUTED BY (C1);

Examples

Create a heap table named FACE_TABLE. C1 is the primary key column, and C2 is the vector column.

CREATE TABLE FACE_TABLE (  
    C1 INT,  
    C2 REAL[] NOT NULL,  
    C3 TIMESTAMP NOT NULL,  
    C4 VARCHAR(20) NOT NULL,  
    PRIMARY KEY (C1)
) DISTRIBUTED BY (C1);