skip to Main Content

I have below table with schema , i want to generate some 10K or 20K test data and i want the test data values as per related column data type , anyone can you please suggest on this , in this table i want the test data for ID unique values for each row , but am fine with migration_id values can be same for more than one row

CREATE TABLE student_services ( id uuid NOT NULL, mobile_type VARCHAR(10) NOT null, migration_id uuid NOT NULL, service_type text NOT NULL, s_config jsonb NOT NULL, subs_id uuid NULL, expire_at timestamp NOT NULL );

i tried with some scripts but am failing to handle UUID type

2

Answers


  1. the UUID values can be generated by using the uuid extension:

    CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
    

    and then you can simply generate the UUID using the function

    uuid_generate_v4();
    

    For rest of the data you can generate using any external program in java/node/python or import it from an excel/csv

    Login or Signup to reply.
  2. If you’re using PostgreSQL 13 or above, you can use gen_random_uuid() to generate random UUIDs.

    For older version, you would need to use the uuid-ossp extension, as described in @vaibhav’s answer. The downside is that CREATE EXTENSION ... needs to be done as a database superuser first.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search