Double prepare

From: Igor Korot <ikorot01(at)gmail(dot)com>
To: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Double prepare
Date: 2026-05-16 06:40:32
Message-ID: CA+FnnTycS2E-Bb7Wm+-mmTXwRQ-t4Wyfg=S2Upysf-zF0ty_2w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi, ALL,
Is there a way to see if the query has been prepared already (in libpq)?

Trying to avoid a following scenario (pseudo-code):

[code]
int main()
{
test();
test();
}

void test()
{
PGresult *res = PQprepare( conn, "my query", "SELECT * FROM
my_table", /* rest of params */ );
PQclear( res );
}
[/code]

I presume there is a penalty for that even if the code succeeds.

Or is it better to run PQprepare for all known parameterized queries
in the very beginning of the program and just execute them when needed?

Thank you.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2026-05-16 13:46:27 Re: Double prepare
Previous Message Isaac Morland 2026-05-16 02:15:25 Re: Suggestion for Easier Cross-Database Query Handling in PostgreSQL