Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "ERROR: column c.relhasoids does not exist" in Postgres?

Tags:

postgresql

I’m trying to CREATE TABLE command in Postgresql. After creating a table, if I punch in TABLE table name, it works.

But I punch in \d table name, I keep getting an error below.

ERROR: column c.relhasoids does not exist LINE 1: ...riggers, c.relrowsecurity, c.relforcerowsecurity, c.relhasoi...

I attempted DROP DATABASE table name recreated a database and recreated a table again several times. But it didn't work.

Any suggestions would be appreciated! Thank you.

like image 873
Nao Avatar asked Oct 19 '19 06:10

Nao


People also ask

How do I edit columns in PostgreSQL?

The syntax to modify a column in a table in PostgreSQL (using the ALTER TABLE statement) is: ALTER TABLE table_name ALTER COLUMN column_name TYPE column_definition; table_name. The name of the table to modify.

Is exists in Postgres?

The PostgreSQL EXISTS condition is used in combination with a subquery and is considered "to be met" if the subquery returns at least one row. It can be used in a SELECT, INSERT, UPDATE, or DELETE statement.

Does add column lock table Postgres?

1: Never add a column with a default value Adding a column takes a very aggressive lock on the table, which blocks read and write. If you add a column with a default, PostgreSQL will rewrite the whole table to fill in the default for every row, which can take hours on large tables.

Does number of columns affect performance in Postgres?

Yes the number of columns will - indirectly - influence the performance. The data in the columns will also affect the speed.


1 Answers

I am able to reproduce your error if I am using Postgres v.12 and an older client (v.11 or earlier):

[root@def /]# psql -h 172.17.0.3 psql (11.5, server 12.0) WARNING: psql major version 11, server major version 12.          Some psql features might not work. Type "help" for help.  postgres=# create table mytable (id int, name text); CREATE TABLE postgres=# table mytable;  id | name  ----+------ (0 rows)  postgres=# \d mytable; ERROR:  column c.relhasoids does not exist LINE 1: ...riggers, c.relrowsecurity, c.relforcerowsecurity, c.relhasoi...                                                              ^ postgres=#  

This is because in v. 12, table OIDs are no longer treated as special columns, and hence the relhasoids column is no longer necessary. Please make sure you're using a v. 12 psql binary so you don't encounter this error.

You may not necessarily be using psql, so the more general answer here is to make sure you’re using a compatible client.

like image 121
richyen Avatar answered Sep 19 '22 14:09

richyen