sqlalchemy不执行对架构的注释 [英] sqlalchemy not executing Comment on schema

查看:203
本文介绍了sqlalchemy不执行对架构的注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定为什么对模式的注释不能通过sqlalchemy工作,
却可以在psql控制台上正常工作,



尝试了各种设置仍然没有运气好,架构已创建但无法添加描述。

  import sqlalchemy 

engine = sqlalchemy.create_engine('postgresql:// postgres @ localhost / posgres')
engine.execute(如果不存在myschema,则创建SCHEMA)
engine.execute( SCHEMA myschema上的注释'似乎随机描述')

使用psql检查

  postgres =#\dn + 
模式列表
名称│所有者│访问权限│描述
──────────┼────────┼────────┼ ───────────────────
myschema│postgres││
public│postgres│postgres = UC /postgres↵│标准的公共架构
││= UC / postgres│
(2行)


解决方案

不确定为什么,但是一旦创建连接并运行 COMMIT



< pre class = lang-py prettyprint-override> 在[8]中:conn = engine.connect()

在[9]中:conn.execute( COMMENT ON SCHEMA myschema是'似乎随机描述')
Out [9]:< sqlalchemy.engine.result.ResultProxy at 0x7fd109991cd0>

输入[10]:conn.execute( COMMIT;)
输出[10]:< sqlalchemy.engine.result.ResultProxy at 0x7fd0ff3b7d10>



  postgres =#\ dn + 
模式列表
名称|业主|访问权限|说明
---------- + ---------- + ---------------------- + ---------------------------
myschema | postgres | |似乎是随机说明
public | postgres | postgres = UC / postgres + |标准公共架构
| | = UC / postgres |


I'm not sure why comment on schema is not working via sqlalchemy, but works perfectly on psql console,

Have tried various settings still no luck, schema gets created but cannot add description.

import sqlalchemy

engine = sqlalchemy.create_engine('postgresql://postgres@localhost/posgres')
engine.execute("CREATE SCHEMA IF NOT EXISTS myschema")
engine.execute("COMMENT ON SCHEMA myschema IS 'Seemly Random Description'")

checking with with psql

postgres=# \dn+
                           List of schemas
   Name   │  Owner   │  Access privileges   │      Description       
──────────┼──────────┼──────────────────────┼────────────────────────
 myschema │ postgres │                      │ 
 public   │ postgres │ postgres=UC/postgres↵│ standard public schema
          │          │ =UC/postgres         │ 
(2 rows)

解决方案

Not entirely sure why, but it appears to work once you create a connection and run COMMIT:

In [8]: conn = engine.connect()                                                                                                                                                                              

In [9]: conn.execute("COMMENT ON SCHEMA myschema IS 'Seemly Random Description'")                                                                                                                            
Out[9]: <sqlalchemy.engine.result.ResultProxy at 0x7fd109991cd0>

In [10]: conn.execute("COMMIT;")                                                                                                                                                                             
Out[10]: <sqlalchemy.engine.result.ResultProxy at 0x7fd0ff3b7d10>

postgres=# \dn+
                            List of schemas
   Name   |  Owner   |  Access privileges   |        Description        
----------+----------+----------------------+---------------------------
 myschema | postgres |                      | Seemly Random Description
 public   | postgres | postgres=UC/postgres+| standard public schema
          |          | =UC/postgres         |

这篇关于sqlalchemy不执行对架构的注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆