Adding a key to an empty hstore column

后端 未结 4 1082
礼貌的吻别
礼貌的吻别 2021-02-02 13:30

According to the postgres documentation, you add a key to an hstore column as follows:

UPDATE tab SET h = h || (\'c\' => \'3\');

But it seem

4条回答
  •  情书的邮戳
    2021-02-02 13:33

    To avoid this you need to ensure the hstore is created as empty and not null. You can add an empty hstore to an existing table:

    ALTER TABLE htest ADD h HSTORE NOT NULL DEFAULT '';
    

    Or you can alter your existing hstore to empty:

    ALTER TABLE htest ALTER COLUMN h SET NOT NULL;
    ALTER TABLE htest ALTER COLUMN h SET DEFAULT '';
    

    Please note that exiting values cannot be null when you set the column to 'NOT NULL'.

提交回复
热议问题