Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tEsWp-00AG1X-Jc for pgsql-general@arkaria.postgresql.org; Sat, 23 Nov 2024 15:58:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tEsWn-001itt-B5 for pgsql-general@arkaria.postgresql.org; Sat, 23 Nov 2024 15:58:33 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tEsWm-001itk-Vb for pgsql-general@lists.postgresql.org; Sat, 23 Nov 2024 15:58:32 +0000 Received: from mail-yb1-xb31.google.com ([2607:f8b0:4864:20::b31]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tEsWg-003OWn-Ft for pgsql-general@lists.postgresql.org; Sat, 23 Nov 2024 15:58:31 +0000 Received: by mail-yb1-xb31.google.com with SMTP id 3f1490d57ef6-e3873c7c9b4so3436529276.3 for ; Sat, 23 Nov 2024 07:58:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732377505; x=1732982305; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=RTwODSmevB4TSitY8F2Tho5lI1mqJcw/MhuIPSFUsB0=; b=TY7Z0cKKg4yRm0cRrKPpEltmDTvOhkaInaTpe2fK24ZkAXXhO9asgbOzfvdyS5SFqe klmhb7vEkdlXGvIoCILMEXveEMJ3LpHeoB/1hUWeGsPnILsZSPR2WRVbDP4g7sU6/LYa csVaEcxxfIirPcSPMvA9guKi4b1aRW3OfeBUvUrKmnZ3n57nsdWO5FI0O7bSjff7Enkw TbhDD22LFllLXLdSOte5JA5slun3x4ryIPjF8/tRfW6wpYrvheftwHMNP1+nyUVix4kD SQnVCcDB2X6uUsU5Jt0Vhq+R45uLBg3l0+7T3Pl3QexQ3erTyE6nMgAq6G7F+T1bsgUU A8hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732377505; x=1732982305; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RTwODSmevB4TSitY8F2Tho5lI1mqJcw/MhuIPSFUsB0=; b=dTzgRvNUXI9dG6Iq6CEp/8PpbPmyaOWa21CWI+AruTGQnStSdBM5OnpEQ63pi+2eeG MQDO0U3nzYTxuXmdfoYPQeNjYMnm7YfTrFOutSvHspBpo0qNI3o17RkhmZFRmlkKxezV W8zbdzgQl9d+E/bHqMJYgd0lFUnC5BDPCVpAr7VjkdmyDuiDL69dVXy5YspMl+7XfDa5 vSQtuPw6QhxTFcsQ12vpHHOOWCkizKU84/gIQSTsADVGB6b9cHJB6rN6jYICqmEOJJrf hi59/Al24hTWJ7/tDC1cuunYZOlVdQba6+4YyKsshSaMQmBcFL3CDoOvEKvTpFaR/dYv gH/w== X-Gm-Message-State: AOJu0YyGOuNMVFZVCserG/Cp0XOydhzj6OY9Fh543CgKF56rPnFi2TMr irpqR2HI5OAMVcxeyjA4bFEG9Uk79ikX675Lkl21raNm1EeaQyJPLtJZqT02F+L9191203WFCy3 UarkYhEJBE6cjanmpQ0oM+qkHk40= X-Gm-Gg: ASbGnct93iAEyEXT63Hm10F8HfHllUuIWCDSWeJTYxe9+J5XgqxBeJRc7ssoCDctlKG pUIvH6CdgRQlfK8ztmG48ltwUqsw0ciKmycZZLGFhoqbHdi5W8+3toU8ZV5a78rnq X-Google-Smtp-Source: AGHT+IEDt4YbZojCGs08FXGptMJ9T98Q/Fb4/U+CAQjt3c1NsA5ox5waLR8BTUggH71OHQ2iuL68/ToR3FMIv4nOm74= X-Received: by 2002:a05:6902:2749:b0:e38:84d2:8a4e with SMTP id 3f1490d57ef6-e38f8c0ac5cmr6277536276.50.1732377505319; Sat, 23 Nov 2024 07:58:25 -0800 (PST) MIME-Version: 1.0 References: <837985448.725696.1732374064323@sg2000-ap-3> In-Reply-To: <837985448.725696.1732374064323@sg2000-ap-3> From: Pavel Stehule Date: Sat, 23 Nov 2024 16:57:49 +0100 Message-ID: Subject: Re: PQexecParams and "SET TIME ZONE $1" gets 'syntax error at or near "$1" at character 15' To: ma.sao@msa.hinet.net Cc: pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000d2555906279691ec" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000d2555906279691ec Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi so 23. 11. 2024 v 16:01 odes=C3=ADlatel napsal: > I get get this same error > > syntax error at or near "$1" at character 15 > > if I feed "const char *command" with the following texts. > > SET TIME ZONE $1 > SET TIME ZONE $1::TEXT > > For some reasons, I can not add quotes around $1 as follows. > > SET TIME ZONE '$1' > SET TIME ZONE '$1'::TEXT > > Statements like "SELECT ... WHERE $1=3D..." have been working flawlessly. > > It looks like PQexecParams doesn't handle statement with "SET ... $1". > > Are there workarounds for me or PQexecParams needs improvement? > This statement has no plan, and then doesn't support parametrization. you can use a function set_config instead https://www.postgresql.org/docs/current/functions-admin.html#FUNCTIONS-ADMI= N-SET SELECT set_config('timezone', $1, false) Regards Pavel > Thank you! > > --- =E6=9C=AC=E9=83=B5=E4=BB=B6=E4=BE=86=E8=87=AAHiNet WebMail --- > --000000000000d2555906279691ec Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi

so 23. 11. 2024 v=C2=A016:01 odes=C3=ADlatel = <ma.sao@msa.hinet.net> na= psal:

I get g= et this same error

syntax error at or near "$1" at charact= er 15

if I feed "const char *command" with the following t= exts.

SET TIME ZONE $1
SET TIME ZONE $1::TEXT

For some reasons, I can not add quotes around $1 as follows.

SET TIME ZONE '$1'
SET TIME ZONE '$1'::TEXT

Statements like "SELECT ... WHERE $1=3D..." have been working = flawlessly.

It looks like PQexecParams doesn't handle statement = with "SET ... $1".=C2=A0

Are there workarounds for me or PQexecParams needs improvement?

This statement has no plan, and then doesn't support param= etrization.


SELECT set_config(= 'timezone', $1, false)

Regards

Pavel


=C2=A0

Thank you!


--- =E6=9C=AC=E9= =83=B5=E4=BB=B6=E4=BE=86=E8=87=AAHiNet WebMail ---
--000000000000d2555906279691ec--