推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
p8p8
V2EX  ›  Python

关于数据库表,多条查询的问题。

  •  
  •   p8p8 · Dec 3, 2014 · 3728 views
    This topic created in 4207 days ago, the information mentioned may be changed or developed.
    user表里有N条记录,表里有3个字段,uid, username, avatar,这个时候,客户端post给服务端一个用户uid的字典,例如{123,332,190,201},那么我如何根据这些传过来的uid,查询到数据后,返回给客户端这4个uid数据库表字段中的username和avatar啊?
    4 replies    2014-12-03 23:58:56 +08:00
    saximoer
        1
    saximoer  
       Dec 3, 2014
    返回几个User 对象的LIST 或者转成JSON 呗~
    不晓得有没有帮助
    maroon
        2
    maroon  
       Dec 3, 2014   ❤️ 1
    select * from user where id in (1,2,3,4);
    p8p8
        3
    p8p8  
    OP
       Dec 3, 2014
    @tornado.gen.coroutine
    def get_myfriens(self,friends):
    query = 'SELECT username, avatar_url FROM users WHERE mid IN (759428,480672);'
    cursor = yield self.execute(query)


    这样会报错:

    psycopg2.ProgrammingError: operator does not exist: text = integer
    LINE 1: SELECT username, avatar_url FROM users WHERE mid in (759428,...
    ^
    HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
    p8p8
        4
    p8p8  
    OP
       Dec 3, 2014
    是我自己字段的问题,设置好了,谢谢大家!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3238 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 11:11 · PVG 19:11 · LAX 04:11 · JFK 07:11
    ♥ Do have faith in what you're doing.