hupen paija
hupen paija

Reputation: 9

Postgresql version 12.1 and SERIAL data type

I had a simple table with following syntax.

CREATE TABLE users(
  id SERIAL PRIMARY KEY,
  username TEXT NOT NULL,
  password TEXT NOT NULL
);

Then I inserted a data with:

INSERT INTO users VALUES("Hupen", "hupen123");

Here, according to documentation "id" field should auto increment itself, right? but It's not happening here. I am on Ubuntu.

Upvotes: 0

Views: 301

Answers (1)

GMB
GMB

Reputation: 222702

You want:

INSERT INTO users(username, password) VALUES('Hupen', 'hupen123');

That is:

  • you need to enumerate the target columns for insert, otherwise the database expects you to provide values for all columns

  • strings should be surrounded with single quotes - double quotes stand for identifiers (that's a syntax error in Postgres)

Upvotes: 1

Related Questions