Table in PostgreSQL DB:

id SERIAL PRIMARY KEY, link VARCHAR(128), title VARCHAR(128), summary VARCHAR(2048), content VARCHAR(16384), published TIMESTAMPTZ 

Insert record (Python, py-postgresql):

 insert = _database.prepare( "INSERT INTO SchemaName.TableName (link, title, summary, content, published) VALUES ($1, $2, $3, $4, $5)" ) … insert(link, title, summary, content, published.strftime('%Y-%m-%d %H:%M:%S %z')) # published — datetime, остальное — str 

Execution causes an error:

 could not pack parameter $5::TIMESTAMP WITH TIME ZONE for transfer … LOCATION: CLIENT DETAIL: '2018-11-08 01:38:31 -0500' 

What am I doing wrong?

  • one
    Interestingly, and if you just send published , then the driver will convert the python object into a database object? - gil9red
  • @ gil9red, yes, should do. If the data type in the database is “with timezone”, then it should work out correctly - MaxU
  • Yes, I did. Thank you very much! - MazurE

1 answer 1

You can pass the datetime object as is, the driver will deal with the conversion of the object to the base type:

 ... insert(link, title, summary, content, published)