In mySQL i am able to do
INSERT INTO table_name (column_name1, column_name2) VALUES('John', 'Doe);
As you can see I do not have to mention the ID, how would I do this in postgreSQL.
Thank you
In mySQL i am able to do
INSERT INTO table_name (column_name1, column_name2) VALUES('John', 'Doe);
As you can see I do not have to mention the ID, how would I do this in postgreSQL.
Thank you
Approach #1: You can declare your ID column as Serial In this case it will create an implicit sequence for your column.
Example :
CREATE TABLE MyTable
(
ID serial NOT NULL,
column1 type,
column2 type
}
Approach #2: Or you can manually define a sequence and then assign its next value as Default value for the column.
CREATE SEQUENCE my_sequence START 1;
CREATE TABLE MyTable
(
ID integer DEFAULT nextval('my_sequence'::regclass) NOT NULL,
column1 type,
column2 type
}
This is not because of mysql
that happens. You can make such this kind of query because you have set id
as an auto_increment
column
You can actually do the same thing in postgreSQL by using the serial pseudo data type instead
Example of primary column serial
id serial PRIMARY KEY,