Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eykyy-000475-La for pgsql-general@arkaria.postgresql.org; Wed, 21 Mar 2018 21:09:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1eykyx-0001jE-Kl for pgsql-general@arkaria.postgresql.org; Wed, 21 Mar 2018 21:09:15 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eykyx-0001j3-73 for pgsql-general@lists.postgresql.org; Wed, 21 Mar 2018 21:09:15 +0000 Received: from mail-pg0-x231.google.com ([2607:f8b0:400e:c05::231]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eykyu-0007Z4-Kl for pgsql-general@postgresql.org; Wed, 21 Mar 2018 21:09:13 +0000 Received: by mail-pg0-x231.google.com with SMTP id a19so2422449pgw.6 for ; Wed, 21 Mar 2018 14:09:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=user-agent:from:to:subject:date:message-id:mime-version; bh=9Bm6sLTRzF40e4Xqwif1GQAFQGOPK4LcBo8W1IkysHc=; b=V0JmTdvBSnBiK10EHO1DwAiPefA2dQ8cAqXfYeZN0GxVeEQfS65x81w+I1DrpWFJZ+ PZ2Q18VTn+zwQgYCPdr6gPvi3JtGn1aQX4jp/382XO7OKVAVvGcCCLJsaIX4epE/S0u0 CoOV/K+CxdM1H/vZR/3/siG56v8o8tsx0RUdaKb7VDFLQYTchC2b0RXSqNCDAZaxsUpC X2kzUZa8roW475hoc5i7UXpieCDG81hq2zpc9hzjo6+wWGpyXyC71UvcF28fJXZHwEh4 2XzGNR+bJBQXNZiAVFv7ZRwtV1T4sjyRwUSnlEyRjMh7HuRlmwavcRq7gIcdANIbcZ81 Tbfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:user-agent:from:to:subject:date:message-id :mime-version; bh=9Bm6sLTRzF40e4Xqwif1GQAFQGOPK4LcBo8W1IkysHc=; b=RdAvuCww5dTq3Bk4P5pIL5HHbu5C5052EORaXNtuGl6MIJSTHHliugRT5pzUFLPK9q iS7hpxryUiui/R7J1ccCzKTng9bTaXUGXwOOPfXaRA6QFj4cPnJtXjSCgU1u4Y1wTDnZ b5/S+YTlJSb50MfdZ0lLrEBjTymuJfwy2p1x54+y48lvh0g+B3LjWIykjD2Pabi/W8gg /1Poz4yRtbLyebkoqd98aj4HIGydHCzxW4HwROiFrOvHpLau+TEUm+wqu2YBF420sGK2 fcWtGPUb3cmR+bHpPwRj9A6535x+bp7WYidgrX+zDb2ifEIiWDKx3+7XYIEP7cDqxyy+ L7ew== X-Gm-Message-State: AElRT7FhUR0w3SQ2R2vVAaZ7Eh4fDRIW/0zeNvE1/7p06aJjOPFlG/a6 ZPuH91EtpDhNWe/lPZklq2pKMKfw X-Google-Smtp-Source: AG47ELuTrVEpiAexNkk67bhnik7cDdevWHFfj9l6x8SNfDPDVM+fu/ZrlZTDroc7uJWLkn1j4J/mfg== X-Received: by 10.99.114.77 with SMTP id c13mr15915096pgn.286.1521666550362; Wed, 21 Mar 2018 14:09:10 -0700 (PDT) Received: from tim-desktop (2001-44b8-31f2-bb00-ac1c-40b9-6e09-8d5e.static.ipv6.internode.on.net. [2001:44b8:31f2:bb00:ac1c:40b9:6e09:8d5e]) by smtp.gmail.com with ESMTPSA id q15sm8097467pgv.49.2018.03.21.14.09.08 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Mar 2018 14:09:09 -0700 (PDT) User-agent: mu4e 0.9.18; emacs 25.3.1 From: Tim Cross To: Postgres General Subject: Prepared statements Date: Thu, 22 Mar 2018 08:09:05 +1100 Message-ID: <87o9jhjfv2.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk a simple question I wasn't able to get a clear answer on.... It is general best practice to use prepared statements and parameters rather than concatenated strings to build sql statements as mitigation against SQL injection. However, in some databases I've used, there is also a performance advantage. For example, the planner may be able to more easily recognise a statement and reuse an existing plan rather than re-planning the query. I wasn't sure what the situation is with postgres - is there a performance benefit in using prepared statements over a query string where the values are just concatenated into the string? thanks, Tim -- Tim Cross