On Mon, Dec 07, 2009 at 10:02:39PM +0000, Adrian Klaver wrote: > > Mon Dec 7 13:19:01 2009 : Error: [ourlittle_sql] Couldn't update SQL > > accounting STOP record - ERROR: invalid input syntax for integer: "" > > > > accounting_stop_query = "UPDATE ${acct_table2} \ > > SET > > AcctSessionTime = CASE WHEN '%{Acct-Session-Time}' = '' THEN \ > > (EXTRACT(EPOCH FROM ('%S'::TIMESTAMP WITH TIME ZONE - > > AcctStartTime::TIMESTAMP WITH TIME ZONE \ > > - '%{%{Acct-Delay-Time}:-0}'::INTERVAL)))::BIGINT ELSE > > '%{Acct-Session-Time}' END, \ > > > > I'm not sure what to do... can the query be rewritten in a manner that > > would > > allow for both use cases? > > If I understand correctly the below may work. If %{Acct-Session-Time} is > an empty string it will return NULL otherwise it will return > %{Acct-Session-Time}. > > ELSE > NULLIF('%{Acct-Session-Time}','') END, Thanks, that should work, with a slight modification - explicit cast to 'bigint', because a nullif()'ed '' is still a 'text' by default. The two cases then evaluate like this: pgsql=# select CASE WHEN '' = '' THEN 1234::BIGINT ELSE NULLIF('', '')::BIGINT END AS value; value ------- 1234 (1 row) pgsql=# select CASE WHEN '13' = '' THEN 1234::BIGINT ELSE NULLIF('13', '')::BIGINT END AS value; value ------- 13 (1 row) -- 2. That which causes joy or happiness. -- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general