skip to Main Content

I’ve created table in PostgreSql:

DROP TABLE IF EXISTS es_events;

CREATE TABLE IF NOT EXISTS es_events (
  id SERIAL,
  name VARCHAR (50) NOT NULL,
  version INT NOT NULL,
  data BYTEA NOT NULL
);

now i’m trying to select from this table:

SELECT COALESCE(MAX(version),0)
                            FROM public.es_events
                            WHERE name = 'asd';

but as a result i receive:

ERROR:  column "version" does not exist
LINE 1: SELECT COALESCE(MAX(version),0)
                            ^
HINT:  Perhaps you meant to reference the column "es_events.  version".
SQL state: 42703
Character: 21

i tried to use "es_events. version" but it doesn’r help:

ERROR:  column "es_events.  version" does not exist
LINE 1: SELECT COALESCE(MAX("es_events.  version"),0)
                            ^
SQL state: 42703
Character: 21

What i’m doing wrong? How to select from table ?

# psql --version
psql (PostgreSQL) 13.3 (Debian 13.3-1.pgdg100+1)

2

Answers


  1. Chosen as BEST ANSWER

    There were spaces in create table, after fixing table creation script names started to work corectly:

    CREATE TABLE IF NOT EXISTS es_events (id SERIAL,name VARCHAR (50) NOT NULL,version INT NOT NULL,data BYTEA NOT NULL)
    

  2. According to your error message, you created the table with a column named " version" (with two leading spaces) rather than version.

    You can rename the column:

    ALTER TABLE es_events RENAME "  version" to version;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search