How unique PK value in Postgres?
doug at artsman.com
Tue Feb 1 21:16:19 UTC 2022
you have to create a sequence key generator for each primay key you want.
imagine a table called F_DEFAULT
and a primary key of D_KEY
you create a sequence generator. our naming convention is table_key or. ‘f_default_d_seq_key'
CREATE SEQUENCE IF NOT EXISTS f_default_d_seq_key
then you give the database column a default of ’nextval’ that references the unique key generator.
ALTER TABLE IF EXISTS f_default
ADD COLUMN d_seq integer NOT NULL DEFAULT nextval('f_default_d_seq_key'::regclass);
Arts Management Systems Ltd.
mailto:doug at artsman.com
Phone (403) 650-1978
> On February 1, 2022, at 12:45 PM, Das Goravani <goravanis at gmail.com> wrote:
> When inserting, how do you get Postgres to assign a new, unique, value in the PK column?
> In SQLite you just pass a #NULL in that column and SQLite assigns a value.
> I was importing data into postgres very recently and no matter what I put in the PK column it would not accept it as cause for assigning a value. I tried 0, and NULL and of course a value. It used the values I passed.. they were from SQLite and they were in order, unique, so it worked out OK.
> But in general new work when inserting how do you get it to assign the value?
> Do you use $excludefrominserts ? That didn’t seem to work on a Smartlist with $doinserts(). I tried it, it came up with errors for the PK field anyway, even though I excluded it.
> Das Goravani
> Manage your list subscriptions at https://lists.omnis-dev.com
> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com
More information about the omnisdev-en