Can't add column in pgAdmin4 and PostgreSQL 9.5.25 - postgresql

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?

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

Alter Type in PgSQL to rename attribute not working

I am trying to rename an attribute of a Type in PgSQL using following Alter command
ALTER TYPE typeName
RENAME ATTRIBUTE attrNameOld TO attrNameNew
CASCADE
PgSQL version is 9.5, running on Ubuntu 16.04
However, I receive following error on my Pgsql CLI
ERROR: relation "<typeName>" does not exist
Please help. Thanks.
So, I can't rename an Attribute in PostgreSQL version <10. Thanks to Stephen for sharing the stackoverflow answer.
Alternatives are available though
Remove the Type. Create anew with right Values, and update Table references
Update Catalogs

PostGIS installed, but unable to select version or add geography columns

I've got an existing Postgres 9.6 database on Google Cloud that has the PostGIS extension enabled, however whenever I try to create a table with a column with the geography type or select the PostGIS version I get an error.
For creating the geography column the error is non-descriptive — just an arrow pointing to the word geography in the following statement
create table place(coordinate geography(POINT,4326));
The version error looks as follows:
select postgis_full_version();
ERROR: could not access file "$libdir/postgis-2.3": No such file or directory
CONTEXT: SQL statement "SELECT postgis_lib_version()"
PL/pgSQL function postgis_full_version() line 22 at SQL statement
The create extension statement confirms it is already installed though e.g
create extension postgis;
error: the extension already exists
I've tried running these commands as the postgres user and as another user who's been granted permissions on the database in question but neither seem to work. Any help would be appreciated.
It's simpler than you think:
Your hosting privider has goofed up the PostGIS installation.
It looks like the file is really missing, or something else on the operating system level is misconfigured.
You should gripe at Google.

Trying to set constraint - new primary key in table, but getting an error: column "amgettuple" does not exist (pgadmin3)

I am creating a new table using pgadmin3 and when I click on constraints to add a primary key, I get this error:
I searched on google but I'm not finding this "amgettuple" issue. Does anyone know what this means? I am new to postgres and using pgadmin, just set it up an hour ago.
Postgres version: 9.6
pgadmin version: 1.22.2
linux mint 18
Install pgAdmin 4. pgAdmin III was supported up to 9,5 version I think.
I am also using pgAdmin 3 and got that error. I fixed it by using the Query Tool:
ALTER TABLE table_name
ADD primary key (column_name);

PhpStorm - ERROR: type "hstore" does not exist

I use primary pgAdmin to browse and edit my PostgreSQL database. Now I would like to use PhpStorm.
In PhpStorm I can browse my tables, but I can not edit data. When I try I get error:
[42704] ERROR: type "hstore" does not exist
Kde: compilation of PL/pgSQL function "on_update" near line 3
Function on_update is on update trigger and it save old row to history table and it uses hstore type.
PhpStorm uses postgresql-9.4-1201.jdbc4.jar driver. I don't know if it is driver error or PhpStorm error. I know that in pgAdmin it works and in PhpStorm not.
I work with same environment as Vojtěch and I have found that the extension is indeed created and present. But in different schema (public) then the current connection operates (the PostgreSQL search_path). There is probably bug in PhpStorm as its not respecting PostgreSQL user's default search_path.
Some workarounds (for DB console only):
In database console you use RESET SEARCH_PATH; statement.
You can enforce search_path on JDBC connection, see the question.

pgadmin drop sequence

In an SQL script I declare:
drop sequence if exists my_sequence_seq cascade;
pgadminIII, version 1.14.3 displays the following error:
the relation my_sequence_seq already exists
I don't see my mistake.
The error message doesn't make any sense. That's what you get when trying to create a sequence that already exists.
Maybe some weird mistake in the old version of pgAdmin 1.14.3? Try upgrading to the current version pgAdmin 1.16.1.