Re: Primary key data type: integer vs identity

Поиск
Список
Период
Сортировка
От Adrian Klaver
Тема Re: Primary key data type: integer vs identity
Дата
Msg-id 2752f2d1-2cec-1df4-21f7-b0b004f8e500@aklaver.com
обсуждение исходный текст
Ответ на Re: Primary key data type: integer vs identity  (Ken Tanzer <ken.tanzer@gmail.com>)
Ответы Re: Primary key data type: integer vs identity  (Ken Tanzer <ken.tanzer@gmail.com>)
Список pgsql-general
On 4/19/19 12:35 PM, Ken Tanzer wrote:

> 
> Thanks Adrian.  You are as usual correct.  (I had a bunch of tables 
> created by a function that I assumed were serial, but were not.)  
> Identity columns still seem tidier and more manageable.  Can you tell if 
> the function I referenced would change the ownership or not?

I believe in 'when it doubt try it, whats the worst that can happen?:)':

<NOTE> I needed to be a superuser to run due to this:
ERROR:  permission denied for table pg_depend
CONTEXT:  SQL statement "UPDATE pg_depend
     SET deptype = 'i'
     WHERE (classid, objid, objsubid) = ('pg_class'::regclass, seqid, 0)
       AND deptype = 'a'"
PL/pgSQL function upgrade_serial_to_identity(regclass,name) line 31 at 
SQL statement


test=# create table serial_test(id serial, fld_1 text);
CREATE TABLE
test=# \dp serial_test
                                 Access privileges
  Schema |    Name     | Type  | Access privileges | Column privileges | 
Policies
--------+-------------+-------+-------------------+-------------------+----------
  public | serial_test | table |                   |                   |
(1 row)

test=# select upgrade_serial_to_identity('serial_test', 'id');
  upgrade_serial_to_identity
----------------------------

(1 row)

test=# \d serial_test
                          Table "public.serial_test"
  Column |  Type   | Collation | Nullable |             Default 

--------+---------+-----------+----------+----------------------------------
  id     | integer |           | not null | generated by default as identity
  fld_1  | text    |           |          |


test=# \dp+ serial_test
                                 Access privileges
  Schema |    Name     | Type  | Access privileges | Column privileges | 
Policies
--------+-------------+-------+-------------------+-------------------+----------
  public | serial_test | table |                   |                   |
(1 row)

> 
> Cheers,
> Ken
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com



В списке pgsql-general по дате отправления:

Предыдущее
От: Ken Tanzer
Дата:
Сообщение: Re: Primary key data type: integer vs identity
Следующее
От: Ken Tanzer
Дата:
Сообщение: Re: Primary key data type: integer vs identity