ERROR: function policies_are(unknown, unknown, unknown) is not unique - postgresql

I am getting below error while running test on pgtap in postgresql. Here I am using "function policies_are" to test my policy which I have created to enable ROW LEVEL SECURITY.
In this case I am running below test case:-
BEGIN;
CREATE EXTENSION pgtap;
select plan(1);
SELECT policies_are( 'public', 'employee', 'emp_rls_policy' );
select * from finish();
ROLLBACK;
I found below reference to test this function:-
https://pgtap.org/documentation.html#policies_are
The same error I am getting for running below 2 functions as well:-
policy_cmd_is()
policy_roles_are()
Error:-
ERROR: function policies_are(unknown, unknown, unknown) is not unique
LINE 1: SELECT policies_are( 'public', 'employee', 'emp_rls_policy' ...
^
HINT: Could not choose a best candidate function. You might need to add explicit type casts.

Related

Redshift ERROR: invalid input syntax for type numeric:

Below is the original code from oracle DB
select
decode(acc_number,
'', acc_number,
'123'||acc_number) as acc_number
from table1
i want to convert it on redshift and it is not working
ERROR: invalid input syntax for type numeric:
i try to cast '123' into numeric
select
decode(acc_number,
'', acc_number,
'123'::numeric||acc_number) as acc_number
from table1
but it still not working
update on using case when on redshift
select
case when acc_number = '' then acc_number
else '123'||acc_number
end
from table1
same error
ERROR: invalid input syntax for type numeric:

DB2 throw exception in case block

In my trigger I want to throw an exeption, but it is not working properly, got exception. Using DB2 LUW
{0:0} An unexpected token "SQLSTATE '1234'" was found following "
SIGNAL". Expected tokens may include: "<space>".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.28.11
CREATE OR REPLACE TRIGGER "TRG_ABC_DELETE_CHECK"
 NO CASCADE BEFORE DELETE ON ABC
REFERENCING OLD AS OLD_OBJ
FOR EACH ROW MODE DB2SQL
BEGIN
SELECT CASE WHEN (SELECT 1 FROM ABC WHERE ID = 2 OR NAME = 'AA' AND OLD_OBJ.TYPE = 2) THEN
SIGNAL SQLSTATE '1234' ('Wrong Parameters');
END FROM SYSIBM.SYSDUMM1;
END
You can't use another statements (like SIGNAL) in the SELECT statement.
Use the RAISE_ERROR function instead to make SELECT raise an exception conditionally.
Or use CASE statement instead of the CASE expression you use in the question.

Database-migration ms sql to postgresql

I am getting a syntax error when converting between SQL Server to PostgreSQL. Any thoughts?
IF (var_port_with_bmrk_total_mv != 0 AND var_bmrk_info IS NOT NULL) THEN
BEGIN
insert into t$tmp_diff
select #asof_dt asof_dt,#choiceID choiceID ,p.input_array_type ,p.group_order, CONVERT(DECIMAL(32,10),p.port_value/#var_port_total_mv) port_value,convert(decimal(32,10), isnull(bmrk_value/#port_with_bmrk_total_mv,0)) bmrk_value
from t$tmp_port_sum p, t$tmp_bmrk_sum b
where p.input_array_type=b.input_array_type and p.group_order = b.group_order
END;
ELSE
Original before conversion
insert into #tmp_other_diff
select #asof_dt asof_dt,#choiceID choiceID , b.input_array_type,b.grouping,convert(decimal(32,10),0) port_value, (bmrk_value/#port_with_bmrk_total_mv) bmrk_value
from #tmp_bmrk_other_sum b
where b.key_value not in ( select p.key_value from #tmp_port_other_sum p)
Error message:
Error occurred during SQL query execution
Reason:
SQL Error [42601]: ERROR: syntax error at or near ","
Position: 9030
the relevant comma being:
CONVERT(DECIMAL(32,10),p.port_value
There is no convert() function in Postgres. Use the SQL standard cast or the Postgres extension ::data type. In this case:
...., cast(0 as decimal(30,10)) port_value, ....
OR
...., 0::decimal(30,10) port_value, ...
Note: No comma after the expression. In the original port_value is the column alias. You need to keep it that way.

Error when ignoring accents in full text search using Ecto and PostgreSQL

I have this search function in my controller:
def search(query, search_term) do
(from u in query,
where: fragment("(to_tsvector('portuguese', unaccent(?)) ## plainto_tsquery(?))", u.name, ^search_term),
order_by: fragment("ts_rank((to_tsvector('portuguese', unaccent(?)), plainto_tsquery(?))) DESC", u.name, ^search_term))
end
I'm getting this error:
ERROR (undefined_function): function unaccent(character varying) does not exist
I've also added the unaccented extension to PostgreSQL with:
CREATE EXTENSION unaccent;
How to make this work?

SQL Command failed with: ERROR: operator does not exist: character varying?

i am trying to get values from database by using following query
SELECT Distinct org.name AS org, sto.ad_org_id AS wh_nearstoredetails_id, sum(sto.qtyonhand) AS qty, pro.name AS product
FROM ad_org org, m_storage_detail sto, m_product pro
WHERE sto.ad_org_id::text = org.ad_org_id::text
AND (sto.m_locator_id::text IN ( select cast(m_locator.m_locator_id as text)
from m_locator,m_warehouse
where m_warehouse.isactive = cast('Y' as varchar)
and m_warehouse.em_ai_warehouseparent::text not like cast('' as text)
and m_warehouse.m_warehouse_id::text = m_locator.m_warehouse_id::text
and m_locator.isdefault = cast('Y' as varchar)))
AND sto.m_product_id::text = pro.m_product_id::text
AND sto.qtyonhand >= cast(1 as numeric)
AND sto.ad_org_id::text IN ( SELECT cast(m_warehouse.ad_org_id as text)
FROM m_warehouse
WHERE m_warehouse.em_ai_warehouseparent::text not like cast('' as text))
GROUP BY org.name,sto.ad_org_id,pro.name
ORDER BY org.name, pro.name;
after creating this i also created a class to call this query and get data but when i deploy my project i am getting following error
WARN - SQL Command failed with: ERROR: operator does not exist: character varying !
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
please help to solve this issue.
i finally found the mistake what i made.
the problem in the above query is i'm trying to make type cast of null value
now i changed the condition to check 'is not null' than "not like ''"
and even i don't need to add cast operation it's useless.
anyways thanks for you response. :)