Re: [HACKERS] psql - add special variable to reflect the last query status - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: [HACKERS] psql - add special variable to reflect the last query status
Date
Msg-id CAFj8pRAL=UhHrZc8q1h1udLJki+9az6E8R2rtLDK_zB+CmYJpQ@mail.gmail.com
Whole thread Raw
Responses Re: [HACKERS] psql - add special variable to reflect the last querystatus  (Fabien COELHO <coelho@cri.ensmp.fr>)
List pgsql-hackers
Hi

2017-04-04 23:01 GMT+02:00 Pavel Stehule <pavel.stehule@gmail.com>:


2017-04-04 22:05 GMT+02:00 Fabien COELHO <coelho@cri.ensmp.fr>:

After some discussions about what could be useful since psql scripts now accepts tests, this patch sets a few variables which can be used by psql after a "front door" (i.e. actually typed by the user) query:

 - RESULT_STATUS: the status of the query
 - ERROR: whether the query failed
 - ERROR_MESSAGE: ...
 - ROW_COUNT: #rows affected

 SELECT * FROM ;
 \if :ERROR
   \echo oops
   \q
 \endif

I'm not sure that the names are right. Maybe STATUS would be better than RESULT_STATUS.

I am sending review of this patch:

1. I agree so STATUS is better name, than RESULT status. Currently it returns values with prefix PGRES (like PGRES_FATAL_ERROR, PGRES_TUPLES_OK). Maybe we should to cut this prefix. FATAL_ERROR, TUPLES_OK looks better for custom level. The PGRES prefix has not sense in psql.

2. I propose availability to read ERROR_CODE - sometimes it can be more practical than parsing error possible translated message

3. The fields ERROR_MESSAGE and ROW_COUNT are set only when it has sense. This behave is maybe too strict for psql and the processing needs more nesting \if command. What do you think about -1 or 0 for ROW_COUNT (for DDL) and "" for ERROR_MESSAGE when there are not any error?  It will be consistent with already implemented LASTOID variable (and other state psql variables). Using default values are not strict clean, but it can reduce complexity of psql scripts. 

4. all regress tests passed
5. there are not any problem with doc building

Regards

Pavel


 

good ideas

Regards

Pavel 


--
Fabien.


--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



pgsql-hackers by date:

Previous
From: Kyotaro HORIGUCHI
Date:
Subject: Re: [HACKERS] asynchronous execution
Next
From: Ashutosh Bapat
Date:
Subject: Re: [HACKERS] [POC] hash partitioning