How to use "COLLECT" in PostgreSQL - postgresql

For COLLECT Im getting error like
ERROR: syntax error at or near "COLLECT"
LINE 48: EXECUTE W_SQL BULK COLLECT
I have written like this
EXECUTE W_SQL BULK COLLECT
INTO STRICT current_setting('pkg_beneficiary.ifsc_fetch_obj')::IFSC_FETCH_STRING;
please help me to solve this error.

Related

Redshift Correlated Subquery within copy command

I am trying to query from a table within a copy command however, I have continually gotten errors. Here is the example SQL statement.
copy schema.table
from 's3://bucket/folder`
iam_role (select value from roles.iam where key = 'IAMRole');
The inner select statement on its own returns a value however, when I run the above, I get the following error:
SQL Error [500310] [42601]: [Amazon](500310) Invalid operation: syntax error at or near "("
The COPY command, as you must suspect, does not support embedded SQL.
If you want to do something like this, you can, but you'll need a procedure.

How to create a trigger before insert in db2

I have three tables below:
I need to create a trigger to disallow students to take a class without completing their pre-requisites (must use a trigger). The trigger must return an error message "Missing Pre-req" when trying to insert a class without its proper pre-req.
So far, I wrote a command below:
create trigger checkPrereq
before insert on HW3.SCHEDULE
referencing new as newRow
for each row
When
(
select GRADE
from HW3.SCHEDULE
where HW3.SCHEDULE.ClassId =
(
select PrereqId from HW3.CLASS_PREREQ
where newRow.ClassId = HW3.CLASS_PREREQ.ClassId
)
) in ('F', null)
begin atomic
set newRow.Semester = null;
signal sqlstate 'KILLED' set message_text = ('Missing Pre-req');
end
but I got a warning:
DB21034E The command was processed as an SQL statement because it was
not a valid Command Line Processor command. During SQL processing it
returned: SQL0104N An unexpected token "GRADE" was found following
"ach row When (select". Expected tokens may include: ")". LINE
NUMBER=1. SQLSTATE=42601
I can not understand what was happening here. Could you please help fix this? Any help is appreciated!

Challenges with 'INSERT' query using dblink_exec

I've read the docs repeatedly, but I'm unclear why I keep getting a
ERROR: syntax error at or near "into"
On
SELECT dblink_exec ('dbname=database_test',
insert into public.names (gid,name,"default",class,last_updated,description)
values ('124565555','dblink_test','true','10','2017-01-30 14:14:40.581',null));
Can I not INSERT to a remote db (note: 'database_test' .is on the same server as the database I am working in)
According to docs you should single quote ' sql statement.
SELECT dblink_exec('myconn', 'insert into foo values(21,''z'',''{"a0","b0","c0"}'');');

DB2 query in RazorSQL for getting the next val from a sequence

I am trying to run a DB2 query in RazorSQL for getting the next val from a sequence but getting the following error. Can anybody plz help me out.
VALUES NEXT VALUE FOR SEQ_UPLOAD_MASTER;
ERROR: An undefined object or constraint name was detected.
DB2 SQL error: SQLCODE: -204, SQLSTATE: 42704, SQLERRMC:
DB2INST1.SEQ_UPLOAD_MASTER Error Code: -204
Query = VALUES NEXT
VALUE FOR SEQ_UPLOAD_MASTER
Thanks. I got the solution. I was trying with the wrong syntax. Correct one is
`select nextval for ARCH_TRANCHE.SEQ_UPLOAD_MASTER from sysibm.sysdummy1;`

Perl DBI no prepare

I am using Perl (DBI:ODBC) to connect to Teradata. SQL statement being executed is replace procedure statement.
Teradata ODBC driver doesn't allow to prepare REPLACE PROCEDURE throwing exception.
So, instead of prepare + execute I've tried to use do
$rownum = $con->do("replace procedure ... ");
The problem is that if replace procedure can not be executed (syntax errors, missing objects) then ODBC driver doesn't generate an error. It simply returns recordset with the list of errors.
So if an error occured during replace procedure, then $rownum value will be non zero.
But DBI->do doesn't support return of recordsets.
So, current situation is:
I can't use prepare + execute because of unsupported statement by the driver
I can't use do, because I can't get error list (however I can identify this error by non-zero rows affected value).
Generally: how to fetch results of the query that can't be prepared?
Force DBD::ODBC to use SQLExecDirect instead of SQLPrepare/SQLExecute.
odbc_exec_direct