【问题标题】:using regexp_replace function with sqlalchemy使用带有 sqlalchemy 的 regexp_replace 函数
【发布时间】:2018-12-06 19:51:10
【问题描述】:

我正在尝试在 sql.execute 语句中将 regexp_replace() 函数与 sqlalchemy 一起使用,但我无法使其工作。

from sqlalchemy import create_engine
from pandas.io import sql

engine =create_engine('postgresql+psycopg2cffi://...')
sql.execute("""create view test as select name,
regexp_replace(name, '\\s\\(([0-9]+)\\)$', '') as name2
from table""", engine)

我想我需要为它定义一个函数,但我是 python 新手,不知道它是如何工作的。

【问题讨论】:

  • 您介意告诉后端数据库服务器吗?还有什么错误?
  • 您好,这是亚马逊红移服务器。我没有收到任何错误,只是功能不起作用。当我直接在数据库中运行相同的查询时,它工作正常。

标签: python sqlalchemy regexp-replace


【解决方案1】:

你可以试试用引擎执行sql吗?

from sqlalchemy import create_engine
engine = create_engine('postgresql+psycopg2cffi://...')
engine.execute("create view test as select name,regexp_replace(name, '\\s\\(([9]+)\\)$', '') as name2
from table")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-18
    • 2015-07-31
    • 2016-02-23
    • 1970-01-01
    • 2021-10-07
    • 2020-05-15
    • 1970-01-01
    相关资源
    最近更新 更多