Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python中创建Postgres函数_Python_Python 2.7_Postgresql_Psycopg2_Postgresql 9.3 - Fatal编程技术网

在Python中创建Postgres函数

在Python中创建Postgres函数,python,python-2.7,postgresql,psycopg2,postgresql-9.3,Python,Python 2.7,Postgresql,Psycopg2,Postgresql 9.3,我正在尝试从Python在Postgres中创建一个函数。我与postgres数据库的连接使用Psycopg 2,并在其他实例中成功连接。代码: pg_cursor.execute('CREATE OR REPLACE FUNCTION %s.fix_geometry(geometry) \ RETURNS SETOF geometry AS\ $BODY$\ SELECT geom the_geom\ FROM \

我正在尝试从Python在Postgres中创建一个函数。我与postgres数据库的连接使用Psycopg 2,并在其他实例中成功连接。代码:

pg_cursor.execute('CREATE OR REPLACE FUNCTION %s.fix_geometry(geometry) \
    RETURNS SETOF geometry AS\
    $BODY$\
        SELECT geom the_geom\
        FROM \
                (\
                SELECT (st_dump(st_buffer(st_snaptogrid(st_makevalid(the_geom), 0.5), 0))).geom\
                FROM (SELECT geom the_geom FROM st_dump(st_snaptogrid($1, 0.5))) a\
                ) b\
        WHERE geometrytype(geom) = \'POLYGON\' AND st_area(geom) >= 0.01;\

    $BODY$\
       LANGUAGE sql VOLATILE\
       COST 100\
       ROWS 1000;' %(schema)) #line 84

pg_connection.commit()
pg_cursor.execute('ALTER FUNCTION %s.fix_geometry(geometry) OWNER TO analysis' % (schema))
pg_connection.commit()
我得到一个错误:

第84行,在
第1000行;'%(模式))
编程错误:类型几何体不存在

当我在pgAdmin中运行代码时,它会成功执行。我错过了什么


Python2.7,Postgres 9.3

事实证明,错误就在提供的代码片段之外。Postgre在公共模式中具有几何体类型,当我定义此代码的搜索路径时,我只定义了我工作的模式;公共服务不包括在内。所以

pg_cursor.execute('set search_path =  %s, public' % (schema))
pg_connection.commit()

事实证明,错误就在提供的代码段之外。Postgre在公共模式中具有几何体类型,当我定义此代码的搜索路径时,我只定义了我工作的模式;公共服务不包括在内。所以

pg_cursor.execute('set search_path =  %s, public' % (schema))
pg_connection.commit()