Обсуждение: Knowing how many records I just inserted

Поиск
Список
Период
Сортировка

Knowing how many records I just inserted

От
Ron Johnson
Дата:
Hi.

v7.3.3

INSERT INTO T_LANE_TX
SELECT  LANE_TX_ID,
        TX_EXTERN_REF_NO,
[snip]
        UPDATE_TS,
        substring(ACK_DATE from 1 for 8)::date,
        FILENAME_ID
FROM T_LANE_TX2
;
INSERT 0 1241897

Ok, I can see that 1,241,897 rows were inserted into T_LANE_TX.
How can I get that back out to bash, if I'm doing psql scripting?
An env. variable wouldn't work, since it would go away when psql
terminates.

TIA
--
+-----------------------------------------------------------------+
| Ron Johnson, Jr.        Home: ron.l.johnson@cox.net             |
| Jefferson, LA  USA                                              |
|                                                                 |
| "I'm not a vegetarian because I love animals, I'm a vegetarian  |
|  because I hate vegetables!"                                    |
|    unknown                                                      |
+-----------------------------------------------------------------+



Re: Knowing how many records I just inserted

От
"Claudio Lapidus"
Дата:
> How can I get that back out to bash, if I'm doing psql scripting?
> An env. variable wouldn't work, since it would go away when psql
> terminates.

Capture the stdout of the psql command and pipe it through cut in order to
get only the third word of output.

your_shell_variable=`psql -c 'insert into t1 select attrs from t2' | cut -d'
' -f3`


hth,
cl.



>
> TIA
> --
> +-----------------------------------------------------------------+
> | Ron Johnson, Jr.        Home: ron.l.johnson@cox.net             |
> | Jefferson, LA  USA                                              |
> |                                                                 |
> | "I'm not a vegetarian because I love animals, I'm a vegetarian  |
> |  because I hate vegetables!"                                    |
> |    unknown                                                      |
> +-----------------------------------------------------------------+
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>