How to insert CURRENT_TIMESTAMP into a PostGreSQL installation of Drupal

I use drupal and the pgsql database, but after a long search I still can’t figure out how to put CURRENT_TIMESTAMP or now () in the database when inserting a row into the table. Putting now () by default for the column will not work, because drupal will not accept it in the database schema, so this is out of the question.

The current column type is the “timestamp without timezone” or “time without timezone” that the drupal schema accepts. Now the problem is that the date is added there.

I tried:

$now = format_date(time(), 'custom', 'Y-m-d H:i:s');

and pasting it with the string placeholder '% s', but pgsql gave me an error.

I also tried changing the type to an integer and pasting it using the time () php function, and it didn’t work (if I used it on other tables), maybe I will stick to the timestamp as it makes sense.

+3
source share
1 answer

Below you will find my suggestions from the comments on the question.

  • You can use 'now' as a string enclosed in single quotes, but current_timestamp should not be in quotes.
  • If you have a timestamp, you must enclose it in single quotes: '2010-10-10 14:13:22'
  • " ", . , - .
  • , , .
+8

Source: https://habr.com/ru/post/1770453/


All Articles