Обсуждение: batching commands with libpq
hi, is there any way to send multiple commands together (ideally in a single network packet), and then wait for their results, using libpq? i want to save extra round-trips. while postgresql's fe-be on-wire protocol seems to allow it (is it right?), i couldn't find a way with libpq. PQsendQuery(conn, "select timeofday();select timeofday();select timeofday();"); seems to work, but i want to use extended protocol. YAMAMOTO Takashi
yamt@mwd.biglobe.ne.jp (YAMAMOTO Takashi) writes: > is there any way to send multiple commands together (ideally in a single > network packet), and then wait for their results, using libpq? i want to > save extra round-trips. while postgresql's fe-be on-wire protocol seems > to allow it (is it right?), i couldn't find a way with libpq. > PQsendQuery(conn, "select timeofday();select timeofday();select timeofday();"); > seems to work, but i want to use extended protocol. You're out of luck: extended protocol intentionally doesn't allow multiple queries per string. The wire protocol does in theory allow you to send more commands before waiting for the results of the first one, but that's not supported in libpq. The only case you can do in libpq is multiple commands in a PQexec string. regards, tom lane
hi, > yamt@mwd.biglobe.ne.jp (YAMAMOTO Takashi) writes: >> is there any way to send multiple commands together (ideally in a single >> network packet), and then wait for their results, using libpq? i want to >> save extra round-trips. while postgresql's fe-be on-wire protocol seems >> to allow it (is it right?), i couldn't find a way with libpq. > >> PQsendQuery(conn, "select timeofday();select timeofday();select timeofday();"); >> seems to work, but i want to use extended protocol. > > You're out of luck: extended protocol intentionally doesn't allow > multiple queries per string. > > The wire protocol does in theory allow you to send more commands before > waiting for the results of the first one, but that's not supported in > libpq. The only case you can do in libpq is multiple commands in a > PQexec string. thanks for explanation. do you think it's worth extending the libpq api to allow two or more in-flight commands? YAMAMOTO Takashi > > regards, tom lane
yamt@mwd.biglobe.ne.jp (YAMAMOTO Takashi) writes: > do you think it's worth extending the libpq api to allow two or > more in-flight commands? That wouldn't be so much an "extension" as a "total redesign, breaking most existing code". regards, tom lane