How to update PostgreSQL DB timestamp to null in Asterisk? - c

I use ast_update_realtime() to update to PostgreSQL DB.
res = ast_update_realtime("confinfo", "id", "01", "start_time", "NULL", SENTINEL);
But I got an error like this:
[Oct 20 15:44:50] ERROR[30428][C-00000000]: res_config_pgsql.c:169 _pgsql_exec: PostgreSQL RealTime: Query Failed because: ERROR: invalid input syntax for type timestamp with time zone: "NULL"
LINE 1: UPDATE confinfo SET start_time = 'NULL' WHERE id = '01'
^
(PGRES_FATAL_ERROR)
I found the reason is "NULL", not is NULL in SQL string.
How could I correct it?

UPDATE confinfo SET start_time = NULL WHERE id = '01'
instead of
UPDATE confinfo SET start_time = 'NULL' WHERE id = '01'
So you should pass NULL without ""

Instead of providing NULL value you can try put empty string like '' or simply
res = ast_update_realtime("confinfo", "id", "01", "start_time", NULL, SENTINEL);

Related

Creating function in oracle

I am trying to create a function that change the day of a football league; if the match is fixed on saturday then the function update the match day to be the previuos friday, and if the match is fixed on sunday the function update the match date to be on monday. Also the function will show how many rows have been update.
The table I use is as follow:
CREATE TABLE "183400_Matches_Details" (
"183400_Stadiums_id" INTEGER NOT NULL,
"183400_Teams_id" INTEGER NOT NULL,
"183400_Teams_id1" INTEGER NOT NULL,
"183400:Referees_id" INTEGER NOT NULL,
"183400_Matches_number" INTEGER NOT NULL,
"date" DATE NOT NULL,
result VARCHAR2(5) NOT NULL
);
I tried the following statements to build the function, but it always gives me an error:
create or replace function updateDay (
v_number "183400_Matches_Details"."183400_Matches_number"%type)
return date
as
v_fecha "183400_Matches_Details"."date"%type;
begin
SELECT TO_CHAR("date", 'DAY', 'NLS_DATE_LANGUAGE=ENGLISH') as day1 into v_fecha FROM
"183400_Matches_Details"
where "183400_Matches_number" = v_number;
if day1 = 'SATURDAY' then
update "183400_Matches_Details"
set "date" = "date"-1
where "183400_Matches_number" = v_number;
elsif day1 = 'SUNDAY' then
update "183400_Matches_Details"
set "date" = "date"+1
where "183400_Matches_number" = v_number;
end if;
return SQL%ROWCOUNT;
end;
/
select * from "183400_Matches_Details"
DECLARE
v_number "183400_Matches_Details"."183400_Matches_number"%type := &number;
v_total_filas number(8);
BEGIN
v_total_filas := actualizaPrecioCoche(v_number);
DBMS_OUTPUT.put_line('There are ' || v_total_filas || ' updated rows');
END;
/
Any ideas to make it run correctly?=)
I changed your function as it should be. Try below.
CREATE TABLE "183400_Matches_Details"
(
"183400_Stadiums_id" INTEGER NOT NULL,
"183400_Teams_id" INTEGER NOT NULL,
"183400_Teams_id1" INTEGER NOT NULL,
"183400:Referees_id" INTEGER NOT NULL,
"183400_Matches_number" INTEGER NOT NULL,
"datee" DATE NOT NULL,
RESULT VARCHAR2 (5) NOT NULL
);
CREATE OR REPLACE FUNCTION updateDay (
v_number "183400_Matches_Details"."183400_Matches_number"%TYPE)
RETURN DATE
AS
v_fecha "183400_Matches_Details"."datee"%TYPE;
sql_qry VARCHAR2 (400 CHAR);
BEGIN
sql_qry :=
'SELECT TO_CHAR(datee, ''DAY'', ''NLS_DATE_LANGUAGE=ENGLISH'') where "183400_Matches_number"='
|| v_number;
EXECUTE IMMEDIATE sql_qry INTO v_fecha;
IF v_fecha = 'SATURDAY'
THEN
UPDATE "183400_Matches_Details"
SET "datee" = "datee" - 1
WHERE "183400_Matches_number" = v_number;
ELSIF v_fecha = 'SUNDAY'
THEN
UPDATE "183400_Matches_Details"
SET "datee" = "datee" + 1
WHERE "183400_Matches_number" = v_number;
END IF;
RETURN to_date('19000101','yyyymmdd') ;
END;
/
After a second look I realized what your asking is actually quite simple: Given a date that is Sat update it to Fri, and that is Sun update to Mon. This can actually be done in a single SQL statement.
I changed it from a function to a procedure as the purpose is to Update the database, and return the number of rows processed. But as a function it makes the purpose to get the row count and updating the database as a side effect. Names and types (IMHO) should always reflect the purpose of the routine. I did 'return' the row count as an OUT parameter - it being an informational side effect. See fiddle for full example.
create or replace
procedure reschedule_sat_sun_match_details(
p_match_number in "183400_Matches_Details"."183400_Matches_number"%type
, p_rows_updated out number)
as
begin
update "183400_Matches_Details"
set "date" = case to_char("date", 'dy')
when 'sat' then "date"-1 -- Sat update to Fri
when 'sun' then "date"+1 -- Sun update to Mon
end
where to_char("date", 'dy') in ('sat','sun')
and "183400_Matches_number" = p_match_number;
p_rows_updated := sql%rowcount;
end reschedule_sat_sun_match_details;
For day of week values I used the format 'dy' rather than 'day'. The difference being 'dy' returns day name abbreviations with a constant length without padding, while 'day' pads the returned values to the length of the longest day name (to get constant length) thus "sunday" is returned as "sunday " to match the length of "wednesday".
A couple other suggestions. Avoid Mixed Case name and names beginning with numbers. These require double quoting (") on every reference. This becomes a pain to just write and your queries much harder to read and understand. a table name Matches_Details_183400 the exact same information without requiring the quotes. (Yes Oracle will make it upper case in messages it it issues but you can still write it in mixed case if you wish - it will still be the same name.) It gives you no benefit but a lot of pain.
As #hotfix mentioned do not use reserved or keywords as object names. Oracle has documented such words and reserves the right to enforce a specific meaning whenever they choose. If/When they do makes an almost untraceable bug to find.

Snowflake Update table error: Unsupported type for binding argument

I'm trying to update a table via a stored procedure based on the Log_Id passed and update the status and insert today's date timestamp in the table (when the table is updated).
Stored procedure:
...
CREATE OR REPLACE PROCEDURE update_table(P_ETL_STATUS_CODE VARCHAR,P_LOG_ID FLOAT)
RETURNS FLOAT
LANGUAGE JAVASCRIPT
AS
$$
var sql_command1 = "UPDATE ETL_EXECUTION_STATUS_LOG SET ETL_STATUS_CODE = :1,ETL_EXEC_END_TIME = :2 WHERE LOG_ID = :3";
var create_stmt1 = snowflake.execute({sqlText : sql_command1,
binds: [P_ETL_STATUS_CODE,(new Date()),P_LOG_ID].map(function(x){return x === undefined ? null : x})
}
);
return P_LOG_ID;
$$
;
...
call update_table('Test77',47)
But, I'm getting the following error:
Error message: Execution error in stored procedure UPDATE_TABLE: Unsupported type for binding argument Sun Apr 05 2020 18:39:31 GMT-0700 (PDT) At Snowflake.execute, line 3 position 30
The table already contains Log_Id 47. Column 'ETL_EXEC_END_TIME' is timestamp_ntz in table.
Can you suggest where I'm going wrong?
Cheers
JavaScript date format is not compatible with Snowflake's date format. As you can see from the message, JavaScript sends this:
"Sun Apr 05 2020 18:39:31 GMT-0700 (PDT)"
You may convert this to more common date format:
https://stackoverflow.com/a/21482470/12550965
I see that you want to record timestamp. So why don't you use CURRENT_TIMESTAMP command?
CREATE OR REPLACE PROCEDURE update_table(P_ETL_STATUS_CODE VARCHAR,P_LOG_ID FLOAT)
RETURNS FLOAT
LANGUAGE JAVASCRIPT
AS
$$
var sql_command1 = "UPDATE ETL_EXECUTION_STATUS_LOG SET ETL_STATUS_CODE = :1,ETL_EXEC_END_TIME = CURRENT_TIMESTAMP::TIMESTAMP_NTZ WHERE LOG_ID = :2";
var create_stmt1 = snowflake.execute({sqlText : sql_command1,
binds: [P_ETL_STATUS_CODE,P_LOG_ID].map(function(x){return x === undefined ? null : x})
}
);
return P_LOG_ID;
$$
;

invalid input syntax for type timestamp

While running the below code i get an error saying invalid input syntax for type timestamp from admission_datetime.
UPDATE ccsm.stg_demographics_baseline
SET xx_los_days =
(CASE WHEN admission_datetime IS NULL OR
date_trunc('day',admission_datetime) = ''
THEN NULL
WHEN discharge_datetime IS NULL OR
date_trunc('day',discharge_datetime) = ''
THEN date_diff('day', admission_datetime, CURRENT_DATE)
ELSE
date_diff('day', admission_datetime, discharge_datetime)
END);
enter code here
See date_trunc documentation:
The return value is of type timestamp or interval with all fields that are less significant than the selected one set to zero (or one, for day and month).
So you can not compare it with an empty string:
date_trunc('day', admission_datetime) = ''
The invalid input syntax for type timestamp error message concerns the empty string (''), not the admission_datetime column.
Furthermore, there is no date_diff function in PostgreSQL. Just subtract one timestamp from another and you will get an interval result:
SELECT timestamp '2001-09-29 03:00' - timestamp '2001-09-27 12:00'
You'll get
interval '1 day 15:00:00'
If you need the difference in days, try this:
SELECT DATE_PART('day', timestamp '2001-09-29 03:00' - timestamp '2001-09-27 12:00')
The result is 1.
See here for examples of DATEDIFF-like expressions in PostgreSQL.

how to write an expression in SSRS to filter data

I need to filter my result based on Parameter value. If it says "Open" then DueDate column should be = NULL, if says 'Closed' that DueDate = NOT NULL, and if it says "Both" then it should grab all DueDates
I have created query parameter "Status" that gives me 3 possible values:
Next I created report parameter "Status" and Allow Multiple Values
Now I go to my main query and go to Filters:
And here I cant understand how can I write an expression saying:
If report "status" value = "Open" then show me the result where DueDate IS NULL,
If report "Status" value = "Closed" then DueDate IS NOT NULL ,
And If report "Status" value = "Both" then show me all DueDates ( null and not null)
Another thing is I already have case statement in my query:
ALTER Procedure
AS
#ShowOpen bit = 0,
#ShowClosed bit = 0
SELECT
FROM
WHERE
AND
(
(CASE WHEN (#ShowOpen = 1) THEN
CASE WHEN (tblNoteRecipients.CompletedDate IS NULL and tblNoteRecipients.IsDiary = 1) or tblNoteRecipients.UserGUID is null THEN 1 ELSE 0 END
-- CASE WHEN (tblNoteRecipients.CompletedDate IS NULL) THEN 1 ELSE 0 END
ELSE
1
END = 1)
AND
(CASE WHEN (#ShowClosed = 1) THEN
CASE WHEN (tblNoteRecipients.CompletedDate IS NULL) THEN 0 ELSE 1 END
ELSE
1
END = 1)
OR ((#ShowOpen = 1) AND (#ShowClosed = 1))
)
Is any way out of it in SSRS I can create parameter that accepts values Open, Closed and Both?
Added test1
Add a Filter in the tablix like this:
In Expression use:
=IIF(
(Array.IndexOf(Parameters!Status.Value,"Open")>-1 and
Isnothing(Fields!DueDate.Value)) or
(Array.IndexOf(Parameters!Status.Value,"Closed")>-1 and not
Isnothing(Fields!DueDate.Value)) or
(Array.IndexOf(Parameters!Status.Value,"Both")>-1),
"Include","Exclude")
For Value use:
="Include"

Handling NULL value in ORACLE Table Query

I have a question regarding handling NULL value in a column in ORACLE Table.
So, when i query a table, i get this error message in every NULL value occurences
Notice: Undefined index: STATUS in C:\xampp\htdocs\WeltesInformationCenter\AdminLTE\pages\tables\assignmenttable.php on line 481
my query is like this
SELECT MASTER_DRAWING.*, (SELECT PREPACKING_LIST.PACKING_STATUS FROM PREPACKING_LIST WHERE MASTER_DRAWING.HEAD_MARK = PREPACKING_LIST.HEAD_MARK) STATUS FROM MASTER_DRAWING WHERE PROJECT_NAME = :PROJNAME
My question is, how to handle NULL value so that when it sees a null value, it can return some value such as 0 or any string.
Thanks
Try
SELECT MASTER_DRAWING.*,
NVL((SELECT PREPACKING_LIST.PACKING_STATUS
FROM PREPACKING_LIST
WHERE MASTER_DRAWING.HEAD_MARK = PREPACKING_LIST.HEAD_MARK),'N/A'
) STATUS
FROM MASTER_DRAWING WHERE PROJECT_NAME = :PROJNAME

Resources