Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python 的列表不能直接向 []text,caracater varying 存入 #1

Open
pgshow opened this issue Apr 9, 2022 · 3 comments
Open

Comments

@pgshow
Copy link

pgshow commented Apr 9, 2022

python 的列表和字符串变量不能直接向这两个类型存入,不然会报错,可以添加一些自动方法么?

@Boris-code
Copy link
Owner

python 的列表和字符串变量不能直接向这两个类型存入,不然会报错,可以添加一些自动方法么?

没看懂你问题

@pgshow
Copy link
Author

pgshow commented Apr 29, 2022

比如 PostgreSQL 不支持 python 的 bool 类型,必须转换:

def boolean(var):
"""python bool to postgres boolean"""
if not var or not isinstance(var, bool):
return "false"
else:
return "true"

不支持 python 的 list 文本类型,也必须转换:

def list_text(var):
    """python list to []text"""
    if not var or not isinstance(var, list):
        return None

    return '{"' + '","'.join(var) + '"}'

python 字符串需要转 character varying

def str2char_var(var):
"""python string to postgres character varying"""
if not var or not isinstance(var, str):
return None
else:
return f"{var}"

@RuixiangS
Copy link
Collaborator

目前来看比较麻烦,看后面如何做到兼容

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants