After you connect to a database, you can perform database operations such as creating, deleting, modifying, and querying data. This topic describes how to create a table and write 1 million rows of data to the table.

Prerequisites

An AnalyticDB for PostgreSQL instance is created. For more information, see Connect to a database.

Procedure

  1. Create a table named customer.
    Sample statement:
    CREATE TABLE CUSTOMER(id int, name varchar, md5 varchar) DISTRIBUTED BY (id) ;
  2. Create a function used to produce random test data.
    Sample statement:
    CREATE OR REPLACE FUNCTION f_random_str(length INTEGER)
    RETURNS character varying AS $$
    DECLARE
        result varchar(50);
    BEGIN
        SELECT array_to_string(ARRAY(SELECT chr((65 + round(random() * 25)) :: integer)
        FROM generate_series(1,length)), '') INTO result;
    
        return result;
    END;
    $$ LANGUAGE plpgsql;
  3. Insert 1 million rows of random test data to the customer table.
    Sample statement:
    INSERT INTO customer SELECT *, f_random_str(5), md5(random()::text) FROM generate_series(1, 1000000);
  4. Query the total number of rows in the customer table.
    Sample statement:
    SELECT count() FROM customer;

    The following information is returned:

    Number of rows returned

References

For more information about data migration and synchronization, see Overview.

For more information about SQL syntax, see SQL statements.