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 1s00Wv-008onS-5y for pgsql-general@arkaria.postgresql.org; Thu, 25 Apr 2024 14:56:57 +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 1s00Wt-007hZb-RR for pgsql-general@arkaria.postgresql.org; Thu, 25 Apr 2024 14:56:55 +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 1s00Wt-007hZQ-Cp for pgsql-general@lists.postgresql.org; Thu, 25 Apr 2024 14:56:55 +0000 Received: from mail-yw1-x112b.google.com ([2607:f8b0:4864:20::112b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1s00Wq-004bJ1-N3 for pgsql-general@lists.postgresql.org; Thu, 25 Apr 2024 14:56:54 +0000 Received: by mail-yw1-x112b.google.com with SMTP id 00721157ae682-61af74a010aso11021387b3.0 for ; Thu, 25 Apr 2024 07:56:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714057012; x=1714661812; 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=nZmcMhiH6tI7CcFjervW1eK96eY64pnNXaT0uBXwWqY=; b=G9Uqir2lD6XgLlcem90XgT7mk4F7zVAqIpxhKGnv5l7ppZRWZiozX+CiWZm1R8+aVZ NsoCzNq59iXspYvSE1C3FVZq1DWmrURfe+U54u+NouqBPyZpFO9qI+7vg6a0w5u68Ahl wcmo8f2nPrMhKg4loann4tsPjcTturVEfsuB6HC1skIcSl09xxdgJ+VBOPkniAbbLmzb rSyjvtSdke1UXA1kvRHfoARqpgjLPFR3EXPxeTuZRUgxuGNF2UsymHHJtcGf63Q1sMI1 17bQg90PB2fsAPKc5ls8zDHzN5m4lN8GVlrIi1C6lJ3FJaTIEzGD9xiqjq1YBPX/5ohe 253g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714057012; x=1714661812; 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=nZmcMhiH6tI7CcFjervW1eK96eY64pnNXaT0uBXwWqY=; b=dGhTlOtUaVW10eHTzJ0oM8nwMIownljw11EL8FWq09tQaHBY470KkPPnXIyaeNqoB2 iS1uJv5M/Lui+Y9BRj4cGvxPdJbqaGyqyptaI21/OJ1sXcP5fOsH9hWgF9FlZCHqu5VZ H0NmS32AidlFDHv+E/c0Nu++ADGM2b6nzgQKxv0c/qIUdEKhQ2Bkj1OWZdV7AcsTTS42 BcXqOuWk3QW248TriRXFuZoaWQWBeki0Soufg5aTCp4MIjllCtTSCh+nVgPmmxFc48LZ 7hUva2ZWuSLERIK9efTnGP07D+icoUulYDcRmxYjHgkfFnxGBcJVCxEwOMrlYesml/bw 9i5Q== X-Gm-Message-State: AOJu0Yy8dnm8FiTcYYnkM0/cWnAXsqgGJ7SQxQRSElesqS1DCCpMbwaA bJ7Tl9iWkl5eX9a+UMjmbf5mHwtrYDS8j7PW9WewhQZx5HgKDxFDpHwrkFPalBFouRwuERc6w09 UhNqKeFi0BEDpYq2JI9W7hx5yf58= X-Google-Smtp-Source: AGHT+IF30XvAWarW0sSbjDitdnrGyXlmVlJepXGxELky5D7PTtFWD9PZfi4JBvtexmsVcStDHRo5fL8f5b/7HxxIRT0= X-Received: by 2002:a05:690c:f06:b0:61a:fae7:c639 with SMTP id dc6-20020a05690c0f0600b0061afae7c639mr7044291ywb.31.1714057011684; Thu, 25 Apr 2024 07:56:51 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Pavel Stehule Date: Thu, 25 Apr 2024 16:56:14 +0200 Message-ID: Subject: Re: Need some assistance on stored procedures execution using libpq in C To: Sasmit Utkarsh Cc: pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000004e6e830616ecff4c" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000004e6e830616ecff4c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi =C4=8Dt 25. 4. 2024 v 12:57 odes=C3=ADlatel Sasmit Utkarsh napsal: > Hi PostgreSQL Team, > > I'm trying to execute the stored procedure(details along with the program > in the attachment) to fetch the records from the table for the inputs giv= en > in the code as well. I have already created the procedure in the db. But = I > see some strange output when I try to fetch the details from the table > using *PQexecPrepared*, even though there are no records for the given > input. I see that this message nTuples(rows)=3D1 along with procedure > successful execution. How to better handle this? > when it returned probably an empty result set. Please advise > PQ interface is designed for client server communication you should to use SPI API https://www.postgresql.org/docs/current/spi.html Regards Pavel > > *Output:* > > > > > > *sasmit@sasmit-Virtual-Machine:~/test$ ./test_proceduresmain() Connection > to shadow_shc_data database SUCCESSFULmain() nFields(cols)=3D2 > nTuples(rows)=3D1SELECT operation succeeded on Shadow DBmain() blk_size > returned is 7565871* > > *DB:* > > > > > > > > > > > *[nix-shell:/ext/shb/tpfasm/shares-c]$ psql shadow_shc_datapsql (14.9, > server 12.16 (Ubuntu 12.16-0ubuntu0.20.04.1))Type "help" for > help.shadow_shc_data=3D# select * from fs_data;shadow_shc_data=3D# CALL > SQL_select_data_procedure(-335509949,false , NULL, NULL); blksize | > fadata---------+-------- |(1 row)* > > > > > > > > > > > > > > > > > > > > > *shadow_shc_data-# \dfList of functions-[ RECORD 1 > ]-------+----------------------------------------------------------------= -------------------------------------------------Schema > | publicName | sql_insert_data_procedureResul= t > data type |Argument data types | fa integer, ft integer, ord integer, > xaddr text, recid text, blk_size integer, indata bytea, INOUT outdata > byteaType | proc-[ RECORD 2 > ]-------+----------------------------------------------------------------= -------------------------------------------------Schema > | publicName | sql_select_data_procedureResul= t > data type |Argument data types | fa integer, hold boolean, INOUT blksi= ze > integer, INOUT fadata byteaType | proc-[ RECORD 3 > ]-------+----------------------------------------------------------------= -------------------------------------------------Schema > | publicName | sql_update_data_procedureResul= t > data type |Argument data types | indata bytea, unhold boolean, fa > integerType | proc* > > Regards, > Sasmit Utkarsh > +91-7674022625 > --0000000000004e6e830616ecff4c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi

=C4=8Dt 25. 4. 2024 v=C2=A012:57 odes=C3=ADla= tel Sasmit Utkarsh <utkarshsa= smit@gmail.com> napsal:
Hi PostgreSQL Team,

I= 9;m trying to execute the stored procedure(details along with the program i= n the attachment) to fetch the records from the table for the inputs given = in the code as well. I have already created the procedure in the db. But I = see some strange output when I try to fetch the details from the table usin= g PQexecPrepared, even though there are no records for the given inp= ut. I see that this message nTuples(rows)=3D1 along with procedure successf= ul execution. How to better handle this?
when it returned probabl= y an empty result set. Please advise

PQ interface is designed for client server communication
you should to use SPI API


Regards

=
Pavel
=C2=A0

Output:
=
sasmit@sasmit-Virtual-Machine:~/test$ ./test_procedures
main() C= onnection to shadow_shc_data database SUCCESSFUL
main() nFields(cols)=3D2 nTuples(rows)=3D1
SELECT = operation succeeded on Shadow DB
main() blk_size returned is 7565871
=

DB:
[nix-shell:/ext/s= hb/tpfasm/shares-c]$ psql shadow_shc_data
psql (14.9, server 12.16 (Ubun= tu 12.16-0ubuntu0.20.04.1))
Type "help" for help.

shado= w_shc_data=3D# select * from fs_data;
shadow_shc_data=3D# CALL SQL_selec= t_data_procedure(-335509949,false , NULL, NULL);
=C2=A0blksize | fadata<= br>---------+--------
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|

= (1 row)


shadow_shc_data-# \df
List of func= tions
-[ RECORD 1 ]-------+---------------------------------------------= --------------------------------------------------------------------
Sch= ema =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| public
Name =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| sql_insert_data_procedur= e
Result data type =C2=A0 =C2=A0|
Argument data types | fa integer, f= t integer, ord integer, xaddr text, recid text, blk_size integer, indata by= tea, INOUT outdata bytea
Type =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0| proc
-[ RECORD 2 ]-------+-------------------------------= ---------------------------------------------------------------------------= -------
Schema =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| public
Name =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| sql_select_data_procedure
Result da= ta type =C2=A0 =C2=A0|
Argument data types | fa integer, hold boolean, I= NOUT blksize integer, INOUT fadata bytea
Type =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| proc

-[ RECORD 3 ]-------+---------= ---------------------------------------------------------------------------= -----------------------------
Schema =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0| public
Name =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0| sql_update_data_procedure
Result data type =C2=A0 =C2=A0|Argument data types | indata bytea, unhold boolean, fa integer
Type =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| proc


Regards,
Sasmit Utkarsh
+91-76740226= 25
--0000000000004e6e830616ecff4c--