Home > database >  Can't add column in pgAdmin4 and PostgreSQL 9.5.25
Can't add column in pgAdmin4 and PostgreSQL 9.5.25

Time:05-13

I'm working with pgAdmin4 and PostgreSQL 9.5.25 on Ubuntu 16.04 (I know it's outdated but I really need to work on it currently).

I can add a new table to my database, however, when I try to add a new column using GUI (Table --> Properties) to an existing table I get this error message:

ERROR   pgadmin:    Failed to execute query (execute_scalar) for the server #1 - DB:api_dev2 (Query-id: 1319646):
Error Message:ERROR:  syntax error at or near "NOT"
LINE 2:     ADD COLUMN IF NOT EXISTS is_for_sale boolean DEFAULT Fal...
                          ^

The corresponding SQL query is this

ALTER TABLE IF EXISTS public."Products"
    ADD COLUMN IF NOT EXISTS is_for_sale boolean DEFAULT False;

I know that "IF NOT EXISTS" is the source of the problem. When I simply run this query:

ALTER TABLE IF EXISTS public."Products"
    ADD COLUMN is_for_sale boolean DEFAULT False;

it works. But why is this "IF NOT EXISTS" is added by pgAdmin4?

CodePudding user response:

ADD COLUMN IF NOT EXISTS is only available in Postgres 9.6 and up. See the documentation for Postgres 9.5.

To address your edit, the version of PostgreSQL you are using is no longer supported - all supported versions support the ADD COLUMN IF NOT EXISTS syntax which is probably why pgadmin assumes it is fine to use it. You could try to use an older version of pgadmin.

  • Related