Re: reduce number of multiple values to be inserted

From: Rob Sargent <robjsargent(at)gmail(dot)com>
To: tango ward <tangoward15(at)gmail(dot)com>
Cc: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: reduce number of multiple values to be inserted
Date: 2018-05-30 00:29:05
Message-ID: 0478A9B3-9186-45FA-A9B0-303CEBD795C7@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> On May 29, 2018, at 6:10 PM, tango ward <tangoward15(at)gmail(dot)com> wrote:
>
>
> Hi,
>
> I am working on inserting multiple values for a table. I need to insert 3 values of data for each age of the students from the same village. It will be 3 different ages of student per village.
>
> My sample code:
>
>
> curr_pgsql.execute('''
> INSERT INTO student (created, modified, name,
> address, age, level
> )
> VALUES (current_timezone, current_timezone,
> 'Scott', 'Malayan Village', 21, 2),
> (current_timezone, current_timezone,
> 'Ben', 'Malayan Village', 21, 2),
> (current_timezone, current_timezone,
> 'Scott', 'Malayan Village', 21, 2),
>
> (current_timezone, current_timezone,
> 'Andrew', 'Malayan Village', 25, 2),
> (current_timezone, current_timezone,
> 'Larry', 'Malayan Village', 25, 2),
> (current_timezone, current_timezone,
> 'Adam', 'Malayan Village', 25, 2),
>
> (current_timezone, current_timezone,
> 'Elisse', 'Malayan Village', 27, 2),
> (current_timezone, current_timezone,
> 'Xena', 'Malayan Village', 27, 2),
> (current_timezone, current_timezone,
> 'Karen', 'Malayan Village', 27, 2)
>
> I will repeat the same process for 13 villages so that will be 117 of values. I would like to know if there's a way to reduce the script? This has to be done strictly via script.
>
>
> Thanks,
> J
>
Is “current_timezone, current_timezone” just a typo? I think you need to make the 117 data lines and load using \copy

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message tango ward 2018-05-30 00:32:16 Re: reduce number of multiple values to be inserted
Previous Message tango ward 2018-05-30 00:28:09 Re: reduce number of multiple values to be inserted