如何解决如何将 python Int16 作为 smallint 导入 PostgreSQL?
我在 python 中使用 cat three.module.js
...
function resizeImage( image,needsPowerOfTwo,needsNewCanvas,maxSize ) {
...
console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').' );
将 this._renderer.capabilities.maxTextureSize 4096
数据框导入到 psycopg2
数据库。数据框中几列的元素属于 pandas
类型。我是这样导入的:
PostgreSQL
写完之后,我看到数据库中的列的类型为 <class 'numpy.int16'>
,而只需要一个 df.to_sql(table_name,engine,method='multi',if_exists=if_exists_opt_loc,index=False)
来存储 bigint
值。
如何进行导入以使列的类型为 smallint
?谢谢!
解决方法
您也应该添加 dtype 参数:
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_sql.html
dtype={'datefld': sqlalchemy.DateTime(),'intfld': sqlalchemy.types.SmallInteger(),'strfld': sqlalchemy.types.NVARCHAR(length=255)
'floatfld': sqlalchemy.types.Float(precision=3,asdecimal=True)
'booleanfld': sqlalchemy.types.Boolean})
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。