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

2014-12-03 18:52:10 +08:00
 p8p8
user表里有N条记录,表里有3个字段,uid, username, avatar,这个时候,客户端post给服务端一个用户uid的字典,例如{123,332,190,201},那么我如何根据这些传过来的uid,查询到数据后,返回给客户端这4个uid数据库表字段中的username和avatar啊?
2838 次点击
所在节点    Python
4 条回复
saximoer
2014-12-03 18:58:20 +08:00
返回几个User 对象的LIST 或者转成JSON 呗~
不晓得有没有帮助
maroon
2014-12-03 21:21:27 +08:00
select * from user where id in (1,2,3,4);
p8p8
2014-12-03 22:22:44 +08:00
@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
2014-12-03 23:58:56 +08:00
是我自己字段的问题,设置好了,谢谢大家!

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/151286

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX