E
E
Eugene Wolf2016-11-22 11:47:04
PostgreSQL
Eugene Wolf, 2016-11-22 11:47:04

How to add an empty row to a table in PostgreSQL?

Good day dear!
There was a need to create empty rows in a Postgres table. For example, we have a table:

id - SERIAL,
title - VARCHAR

You need to add an empty row to the table. That is, a string whose values ​​will be initialized with default values. In general, I do it like this: INSERT INTO table1 (title) VALUES (NULL);since most tables have a title field . But when it comes to tables that do not have a title field , it becomes necessary to override the methods of the class that creates empty rows, and this looks rather strange in terms of code quality.
*In other databases, various "tricks" are rolled, such as INSERT INTO table1 (id) VALUES (NULL);or INSERT INTO table1 () VALUES ();, but PG stubbornly refuses to accept such constructions.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Shelemetiev, 2016-11-22
@Wolfnsex

insert into table1 default values

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question