Reputation: 2343
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)
Upvotes: 0
Views: 1101
Reputation: 2343
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)
Upvotes: 0
Reputation: 248305
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;
Upvotes: 1