9951 explained code solutions for 126 technologies


postgresqlHow can I insert an empty array into a PostgreSQL database?


To insert an empty array into a PostgreSQL database, you can use the INSERT statement with the VALUES clause. For example, the following code block inserts an empty array into the mytable table:

INSERT INTO mytable VALUES ('empty_array', ARRAY[]::integer[]);

This will insert a row with a column named empty_array and the value of the column will be an empty array of integer type.

Code explanation

  • INSERT INTO mytable: this is the statement used to insert a row into a table.
  • VALUES: this clause is used to specify the values to be inserted.
  • ARRAY[]::integer[]: this is the empty array of integer type.

Helpful links

Edit this code on GitHub