postgresql insert null value on query

To insert a NULL value into a PostgreSQL database table column using PHP, you can use the NULL keyword in your INSERT query. For example, the following query inserts a NULL value into the "column_name" column of the "table_name" table:

<?php

$query = "INSERT INTO table_name (column_name) VALUES (NULL)";
$result = pg_query($connection, $query);

Make sure the variable $connection is a valid connection to your postgresql db.

You can also use the pg_insert() function which allows you to insert a row into a table and return the OID assigned to the inserted row.

<?php

$result = pg_insert($connection, 'table_name', array('column_name' => NULL));

In both cases, it's important to check if the query was executed successfully by checking the value of $result, e.g.

<?php

if (!$result) {
  echo pg_last_error($connection);
} else {
  echo "Inserted NULL value successfully.";
}

You can refer to the official documentation for more details