PostgreSQL - Inserting via console view

I'm not sure if this is a change in DataGrip but I'm almost 100% certain that this didn't happen before.

I double-click on a table and add some data:

The first column is ID and it's NULL, it's defined as IDENTITY.

When I press CTRL+ENTER, I'm getting this error:
 

It makes sense, of course, but ID should be auto-generated, shouldn't they?

0
9 comments
Hi,

Are you saying that the identity id column should have been shown with a generated value in the error message despite the constraint restriction? Just trying to understand your point.
0

No, that leaving it NULL shouldn't be a problem to insert the data. I do it with MySQL all the time. Maybe Postgres query shouldn't contain identity columns in this case? 
In MySQL, we see the word <generated>

And that's why I can add it. Somehow in Postgres, adding data through console becomes useless because we have to enter the Identities manually but then you also have to reset the pointer.

I think this could be postgres behaviour, which means when Datagrip creates a query, unless identities are explicitly given, it could omit them from the query.

0

What is your current DataGrip version? I tested the value input of table values with an identity column in data editor, and they are generated automatically. Please also provide the table definition so we can investigate

 

0

And is that postgres?

Here's the DDL of the table:

CREATE TABLE tt
(
  id INTEGER DEFAULT NEXTVAL('tt_id_seq'::REGCLASS) NOT NULL
    CONSTRAINT tt_pk
      PRIMARY KEY,
  contract_id INTEGER NOT NULL,
  started_at  TIMESTAMP,
  ended_at    TIMESTAMP,
  description VARCHAR
);

I am on 2025.1, I've been having weird problems with updating it lately (DG freezing out of nowehere itp.) When I go to “Update and Restart”, I get this:
 

But it won't start again and I usually have to restart the laptop and then 2025.1 is back and I can turn the program on, so for now I'm staying on 2025.1

0

This was solely tested on a PG data source. I tested your definition, and the conflict is caused by contract_id, which by definition, is NOT NULL. The identity generated via a sequence assigns a value in the way it should. You need to specify a non-null value in this column to insert a row. Not seeing any issues here 



As for the performance issue, please report on our tracker:

https://youtrack.jetbrains.com/newIssue?project=DBE

0

How can you have a null on primary key column?

0
Do you mean that the contract id column should not have assigned NULL as default value when nothing was added into the cell? The id column with primary key gets a value assigned based on how the sequence is defined.
0

Contract_id is never null when I add it. Have a look at the screenshot of my first post. THe first non-null number is contract_id

0
Gotcha. I can't reproduce it, so this must have been a very specific case. To narrow it down, please try to create a table with Identity used as auto-generated id column and see how it behaves when adding rows via data editor

https://www.postgresql.org/docs/current/ddl-identity-columns.html

Please also specify your current jdbc driver version, postgres version, and IDE build version in Help - About
0

Please sign in to leave a comment.