Re: Insert records in the tavke only if they are not exist

From: Igor Korot <ikorot01(at)gmail(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Insert records in the tavke only if they are not exist
Date: 2024-12-07 17:59:56
Message-ID: CA+FnnTy7w3jaZCOuMGMMNGySfiTjcHh5D06AUMc+w+i6yoKrMA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi, Adrian,

On Sat, Dec 7, 2024 at 11:18 AM Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> wrote:
>
> On 12/6/24 19:36, Igor Korot wrote:
> > Hi, All,
> >
> > When my application starts up, ot creates some tables and insert records
> > in them.
> >
> > When the app starts for the second time it should check if the tables
> > and the records in them are exist and skip the process.
>
> Does this also apply to starts after the second time?

Yes, it does.

However, if the new table is created in the meantime - the new record
should be created, because it is not there yet.

>
> Is the data expected to change over time?

Data change is possible.

This is one of the tables:

"CREATE TABLE IF NOT EXISTS \"sys.abcatfmt\"(\"abf_name\" char(30)
NOT NULL, \"abf_frmt\" char(254), \"abf_type\" smallint, \"abf_cntr\"
integer" ));";
"CREATE UNIQUE INDEX IF NOT EXISTS pbcatf_x ON
\"sys.abcatfmt\"(\"abf_name\" ASC);";

My understanding is that "INSERT OR IGNORE" will check the unique
index and will not do anything if the recrd
with such data on the index already exists.

>
> >
> > Everything is good, except what if I have a connection from 2 different
> > users?
> Is it possible to have the app start up without external users connecting?

Not sure what you mean here.

Are you asking if the computer can run the app?
Then the answer is NO. App is always started by the user.
Please clarify.

Thank you.

>
> >
> > I can run this inside transaction, but will this be enough? Will stating
> > transaction lock the DB and the second user will wait for transaction to
> > complete?
> >
> > Thank you.
> >
>
> --
> Adrian Klaver
> adrian(dot)klaver(at)aklaver(dot)com
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2024-12-07 18:32:23 Re: Insert records in the tavke only if they are not exist
Previous Message Adrian Klaver 2024-12-07 17:18:48 Re: Insert records in the tavke only if they are not exist