What does mean METRICEU? - sql

I have some codes.
I think this codes are related with dump files(.dmp).
I can not analyse this code.
I want to know what this code means.
Especially, about METRICEU.
METRICSUsynonyms
METRICEU 0
METRICSUviews
CREATE VIEW "VW_OPERRIGHT" ("VCID","OPERATORID","FUNCTIONID") AS
?select vcid,operatorid,functionid from cc_operright
union
select distinct a.vcid,a.operatorid,b.functionid from cc_operrole
a,cc_roleright b where a.roleid=b.roleid
CREATE VIEW "VW_AGENTRESTDETAIL" ("VCID","AGENTID","OPERNAME","AGENTPHONE","GROUPID","CLUSTERID","GROUPNAME"," APPLYTIME","CANCELTIME","AGREETIME","AUDITORNAME","AUDITORID","LEAVESTARTTIME","LEAVEENDTIME","LEAVETIMELEN","AGREELEN","APPLYRESULT","RESTMODE") AS select ard.vcid, ard.agentid,op.opername, ard.agentphone,
... ...
METRICEU 2
METRICSUstored procedures
ALTER SESSION SET "_LOAD_WITHOUT_COMPILE" = PLSQL
ALTER SESSION SET PLSQL_OPTIMIZE_LEVEL = 2 NLS_LENGTH_SEMANTICS = 'BYTE' PLSQL_CODE_TYPE = 'INTERPRETED' PLSQL_DEBUG = TRUE PLSQL_WARNINGS = 'DISABLE:ALL'PLSQL_CCFLAGS = ''
CREATE FORMAT71 PROCEDURE "PR_JUDGERIGHT"
? CREATE procedure pr_judgeright(
+ apprvcid integer,
+ approperid integer,
+ checkedvcid integer,
) checkedoperid integer,
9 retflag out integer,
* retmsg out varchar2,
1 url out varchar2
) is v_count integer;
... ...
TABLE "NGCC_RECORD_WAY"
ANALCOMPUTE TS "NGCC_RECORD_WAY" ANALYZE TABLE "NGCC_RECORD_WAY" ESTIMATE STATISTICS
TABLE "RECTEMPLATE"
ANALCOMPUTE TS "RECTEMPLATE" ANALYZE TABLE "RECTEMPLATE" ESTIMATE STATISTICS
TABLE "TBL_114CALL"
ANALCOMPUTE TS "TBL_114CALL" ANALYZE TABLE "TBL_114CALL" ESTIMATE STATISTICS
TABLE "TBL_114CALL_BAK"
ANALCOMPUTE TS "TBL_114CALL_BAK" ANALYZE TABLE "TBL_114CALL_BAK" ESTIMATE STATISTICS
ENDTABLE
METRICEU 287
METRICEUG0
EXIT
EXIT

Related

Create a BigQuery VIEW for each result in query

I created this query:
SELECT
(SELECT value from UNNEST(project.labels) where key = "project") as project,
ROUND(SUM(cost), 2) as cost
FROM cloud.dataset.billing_export
group by ar
And it returns me something like:
Row | project | cost
1 | PJ1 | 23
2 | PJ2 | 50
Is there a way to create a VIEW for each value (each project)?
I'm trying with UDF and each view must have a name based on the project (eg: view_PJ1) and got something like (but with a lot of errors):
LOOP
SET vars = (SELECT (SELECT value FROM UNNEST(project.labels) WHERE key = "project") AS project
FROM FROM cloud.dataset.billing_export
GROUP BY project);
IF vars=null THEN
LEAVE;
END IF;
CREATE OR REPLACE VIEW `cloud`.`dataset`.AR
AS
SELECT DISTINCT
(SELECT value from UNNEST(project.labels) where key = "project") as project,
ROUND(SUM(cost), 2) as cost
FROM cloud.dataset.billing_export
WHERE project=vars
GROUP BY project;
END LOOP;
Thanks in advance
This is a script that runs inside BigQuery that generates 4 views - giving each view a name coming out of a SQL query:
DECLARE x INT64 DEFAULT 0;
DECLARE rs ARRAY<STRING>;
SET rs = (
WITH data AS (SELECT i FROM `fh-bigquery.public_dump.numbers_255` WHERE i < 4)
SELECT ARRAY_AGG(
'CREATE OR REPLACE VIEW `temp.number' || i
||'` AS SELECT i FROM `fh-bigquery.public_dump.numbers_255` WHERE i=' || i
)
FROM data
);
LOOP
EXECUTE IMMEDIATE(SELECT rs[OFFSET(x)]);
SET x = x + 1;
IF x >= ARRAY_LENGTH(rs) THEN
LEAVE;
END IF;
END LOOP;
The secret is to use EXECUTE IMMEDIATE with a generated string creating the view.

Is it possible to invoke BigQuery procedures in python client?

Scripting/procedures for BigQuery just came out in beta - is it possible to invoke procedures using the BigQuery python client?
I tried:
query = """CALL `myproject.dataset.procedure`()...."""
job = client.query(query, location="US",)
print(job.results())
print(job.ddl_operation_performed)
print(job._properties) but that didn't give me the result set from the procedure. Is it possible to get the results?
Thank you!
Edited - stored procedure I am calling
CREATE OR REPLACE PROCEDURE `Project.Dataset.Table`(IN country STRING, IN accessDate DATE, IN accessId, OUT saleExists INT64)
BEGIN
IF EXISTS (SELECT 1 FROM dataset.table where purchaseCountry = country and purchaseDate=accessDate and customerId = accessId)
THEN
SET saleExists = (SELECT 1);
ELSE
INSERT Dataset.MissingSalesTable (purchaseCountry, purchaseDate, customerId) VALUES (country, accessDate, accessId);
SET saleExists = (SELECT 0);
END IF;
END;
If you follow the CALL command with a SELECT statement, you can get the return value of the function as a result set. For example, I created the following stored procedure:
BEGIN
-- Build an array of the top 100 names from the year 2017.
DECLARE
top_names ARRAY<STRING>;
SET
top_names = (
SELECT
ARRAY_AGG(name
ORDER BY
number DESC
LIMIT
100)
FROM
`bigquery-public-data.usa_names.usa_1910_current`
WHERE
year = 2017 );
-- Which names appear as words in Shakespeare's plays?
SET
top_shakespeare_names = (
SELECT
ARRAY_AGG(name)
FROM
UNNEST(top_names) AS name
WHERE
name IN (
SELECT
word
FROM
`bigquery-public-data.samples.shakespeare` ));
END
Running the following query will return the procedure's return as the top-level results set.
DECLARE top_shakespeare_names ARRAY<STRING> DEFAULT NULL;
CALL `my-project.test_dataset.top_names`(top_shakespeare_names);
SELECT top_shakespeare_names;
In Python:
from google.cloud import bigquery
client = bigquery.Client()
query_string = """
DECLARE top_shakespeare_names ARRAY<STRING> DEFAULT NULL;
CALL `swast-scratch.test_dataset.top_names`(top_shakespeare_names);
SELECT top_shakespeare_names;
"""
query_job = client.query(query_string)
rows = list(query_job.result())
print(rows)
Related: If you have SELECT statements within a stored procedure, you can walk the job to fetch the results, even if the SELECT statement isn't the last statement in the procedure.
# TODO(developer): Import the client library.
# from google.cloud import bigquery
# TODO(developer): Construct a BigQuery client object.
# client = bigquery.Client()
# Run a SQL script.
sql_script = """
-- Declare a variable to hold names as an array.
DECLARE top_names ARRAY<STRING>;
-- Build an array of the top 100 names from the year 2017.
SET top_names = (
SELECT ARRAY_AGG(name ORDER BY number DESC LIMIT 100)
FROM `bigquery-public-data.usa_names.usa_1910_2013`
WHERE year = 2000
);
-- Which names appear as words in Shakespeare's plays?
SELECT
name AS shakespeare_name
FROM UNNEST(top_names) AS name
WHERE name IN (
SELECT word
FROM `bigquery-public-data.samples.shakespeare`
);
"""
parent_job = client.query(sql_script)
# Wait for the whole script to finish.
rows_iterable = parent_job.result()
print("Script created {} child jobs.".format(parent_job.num_child_jobs))
# Fetch result rows for the final sub-job in the script.
rows = list(rows_iterable)
print("{} of the top 100 names from year 2000 also appear in Shakespeare's works.".format(len(rows)))
# Fetch jobs created by the SQL script.
child_jobs_iterable = client.list_jobs(parent_job=parent_job)
for child_job in child_jobs_iterable:
child_rows = list(child_job.result())
print("Child job with ID {} produced {} rows.".format(child_job.job_id, len(child_rows)))
It works if you have SELECT inside your procedure, given the procedure being:
create or replace procedure dataset.proc_output() BEGIN
SELECT t FROM UNNEST(['1','2','3']) t;
END;
Code:
from google.cloud import bigquery
client = bigquery.Client()
query = """CALL dataset.proc_output()"""
job = client.query(query, location="US")
for result in job.result():
print result
will output:
Row((u'1',), {u't': 0})
Row((u'2',), {u't': 0})
Row((u'3',), {u't': 0})
However, if there are multiple SELECT inside a procedure, only the last result set can be fetched this way.
Update
See below example:
CREATE OR REPLACE PROCEDURE zyun.exists(IN country STRING, IN accessDate DATE, OUT saleExists INT64)
BEGIN
SET saleExists = (WITH data AS (SELECT "US" purchaseCountry, DATE "2019-1-1" purchaseDate)
SELECT Count(*) FROM data where purchaseCountry = country and purchaseDate=accessDate);
IF saleExists = 0 THEN
INSERT Dataset.MissingSalesTable (purchaseCountry, purchaseDate, customerId) VALUES (country, accessDate, accessId);
END IF;
END;
BEGIN
DECLARE saleExists INT64;
CALL zyun.exists("US", DATE "2019-2-1", saleExists);
SELECT saleExists;
END
BTW, your example is much better served with a single MERGE statement instead of a script.

Calling function with table valued parameters in Postgres

I have been facing a problem from since morning and have spent many hours but failed to call below given function.
Function definition:
CREATE OR REPLACE FUNCTION public.proc_mc2cdnpf_insertupdatev3(
tblnotesv3 typupdate_notesv3,
tbldoclinks typupdate_guidparameter,
iuserid integer,
shtmltext character varying,
OUT snoteid character varying,
OUT inoteid integer,
OUT inoteactivityid integer)
RETURNS record
LANGUAGE 'plpgsql'
COST 100
VOLATILE
AS $BODY$
#variable_conflict use_variable
declare sNote VARCHAR;
declare sLoggedInUser VARCHAR(20);
declare dtCurrDateTime timestamp;
declare iCurrDate int;
declare iCurrTime INT;
declare iNewNoteID INT;
BEGIN
/*
proc_MC2CDNPF_InsertUpdateV3
2018-04-23 Dennis Sebenick
2018-04-23
- Initial creation of new proc for storing additional HTML text value.
- This proc is going to help bridge the old note system to a new note storage method
2018-04-25
- Added iNoteID / iNoteActivityID for output
2018-06-01
- Update to typUpdate_NotesV3 - removed additional CDN rows for long text
2091-05-08
Rupali Shah
web 1753-added RTRIM(isnull(NOTE_HDQTRS,'')) while creating sNoteID
*/
/******************************
** File: proc_MC2CDNPF_InsertUpdateV3
** Desc: Insert/Update account notes
** Auth: Rupali Shah
** Date: 2019-05-08
**************************
** Change History
**************************
** Date Dev JIRA Description
**2019-05-08 Rupali Shah Web 1753 -added RTRIM(isnull(NOTE_HDQTRS,'')) while creating sNoteID
*******************************/
SELECT dtCurrDateTime = fnGetDate();
SELECT iCurrDate = fnMC2DateToMC2(dtCurrDateTime);
SELECT iCurrTime = fnMC2DateTimeToMC2(dtCurrDateTime);
/*==========================================
Retrieve Update fields from parameter
============================================*/
select
NoteID,
NOTE_NOTES,
NOTE_LOGGEDINUSER,
coalesce(NOTE_ID, 0)
INTO SNoteID,sNote,sLoggedInUser,iNewNoteID
from
tblNotesV3
LIMIT 1;
/************************************************
2018-04-18 DKS
Added in to update new note table
*************************************************/
IF (iNewNoteID > 0)
THEN
BEGIN
IF (LENGTH(sNote) > 0)
THEN
BEGIN
UPDATE
NoteDetails
SET
sNote = sNote,
sNoteHTML = sHTMLText,
iNoteEditedBy = iUserID,
dtNoteEdited = dtCurrDateTime
WHERE
iNoteID = iNewNoteID;
IF (ROWCOUNT = 0)
THEN
BEGIN
INSERT INTO
NoteDetails
(
iNoteType,
sNote,
sNoteHTML,
iNoteEnteredBy,
dtNoteEntered
)
VALUES
( 9, -- iNoteType - int
sNote, -- sNote - VARCHAR(max)
sHTMLText, -- sNoteHTML - VARCHAR(max)
iUserID, -- iNoteEnteredBy - int
dtCurrDateTime
) RETURNING iNewNoteID;
END;
END IF;
END;
END IF;
END;
ELSE
BEGIN
-- Inserting a New Activity
-- 2018-04-18 DKS
-- - Insert to new note table.
IF (LENGTH(sNote) > 0)
THEN
BEGIN
INSERT INTO
NoteDetails
(
iNoteType,
sNote,
sNoteHTML,
iNoteEnteredBy,
dtNoteEntered
)
VALUES
( 9, -- iNoteType - int
sNote, -- sNote - VARCHAR(max)
sHTMLText, -- sNoteHTML - VARCHAR(max)
iUserID, -- iNoteEnteredBy - int
dtCurrDateTime
) RETURNING iNewNoteID;
END;
END IF;
END;
END IF;
/************************************************
End new note table insert / update
*************************************************/
IF EXISTS(SELECT * FROM MC2CDNPF WHERE MC2CDNPF.iNoteID = iNoteID)
THEN
BEGIN
UPDATE
MC2CDNPF
SET
CDNNOTES = '',
CDNFDATE = fnMC2DateToMC2(TblNotesUpdate.NOTE_DDATE),
CDNREASN = TblNotesUpdate.NOTE_REASN,
CDNPRIOR = TblNotesUpdate.NOTE_PRIOR,
CDNTAGGED = TblNotesUpdate.NOTE_TAGGED,
iNoteID = iNewNoteID
FROM
MC2CDNPF
JOIN
tblNotesV3 TblNotesUpdate
ON
MC2CDNPF.iNoteID = TblNotesUpdate.NOTE_ID
WHERE
MC2CDNPF.CDNDSEQN = 1;
END;
ELSE
BEGIN
SELECT
TRIM(coalesce(NOTE_CMPANY,'')) ||
TRIM(coalesce(NOTE_BUSNSS,'')) ||
TRIM(coalesce(NOTE_CUSNBR,'')) ||
TRIM(coalesce(NOTE_ENTITY,'')) ||
TRIM(coalesce(NOTE_HDQTRS,'')) ||
CAST( iCurrDate AS VARCHAR(8)) ||
CAST( iCurrTime AS VARCHAR(10))
INTO sNoteID
FROM
tblNotesV3
LIMIT 1;
INSERT INTO
MC2CDNPF
(
CDNDSEQN,
CDNNOTES,
CDNCMPANY,
CDNCUSNBR,
CDNBUSNSS,
CDNENTITY,
CDNHDQTRS,
CDNRPTCON,
CDNFULNME,
CDNAGNIDN,
CDNDDATE,
CDNDTIME,
CDNREASN,
CDNTUSER,
CDNADATE,
CDNTAGGED,
CDNFDATE,
CDNPRIOR,
CDNDTASRC,
CDNODATE,
CDNOTIME,
iNoteID
)
SELECT
1,
'', -- 6/1/2018 DKS - no longer storing note in MC2CDNPF
coalesce(NOTE_CMPANY,''),
coalesce(NOTE_CUSNBR,''),
coalesce(NOTE_BUSNSS,''),
coalesce(NOTE_ENTITY,''),
coalesce(NOTE_HDQTRS,''),
coalesce(NOTE_RPTCON,''),
NOTE_FULNME,
coalesce(NOTE_AGNIDN,''),
iCurrDate,
iCurrTime,
NOTE_REASN,
NOTE_TUSER,
iCurrDate,
coalesce(NOTE_TAGGED,''),
iCurrDate,
NOTE_PRIOR,
coalesce(NOTE_DTASRC,''),
iCurrDate,
iCurrTime,
iNewNoteID
FROM
tblNotesV3 TblSource;
END;
END IF;
-- There are attachments to link
IF EXISTS(SELECT * FROM tblDocLinks)
THEN
BEGIN
CALL public.proc_Documents_AddLinkMultiple_LinkID (tblDocLinks, 9, 0, sNoteID, iUserID);
END;
END IF;
iNoteID := iNewNoteID;
iNoteActivityID := 0;
END;
$BODY$;
I am trying to call my function in following two ways:
Method1:
SELECT public.proc_MC2CDNPF_InsertUpdateV3
(
(SELECT w::typupdate_notesv3 FROM (TABLE tblnotesv31) w ) ,
(SELECT w1::typupdate_guidparameter FROM (TABLE tbldoclinks1) w1 ) ,
1,
'test text'
)
But it fails with following error:
ERROR: query has no destination for result data
HINT: If you want to
discard the results of a SELECT, use PERFORM instead. CONTEXT:
PL/pgSQL function
proc_mc2cdnpf_insertupdatev3(typupdate_notesv3,typupdate_guidparameter,integer,character
varying) line 41 at SQL statement SQL state: 42601
Method2:
SELECT *
from proc_MC2CDNPF_InsertUpdateV3
(
(SELECT w::typupdate_notesv3 FROM (TABLE tblnotesv31) w ) ,
(SELECT w1::typupdate_guidparameter FROM (TABLE tbldoclinks1) w1 ) ,
1,
'test text'
)
Again it failed saying:
ERROR: query has no destination for result data HINT: If you want to
discard the results of a SELECT, use PERFORM instead. CONTEXT:
PL/pgSQL function
proc_mc2cdnpf_insertupdatev3(typupdate_notesv3,typupdate_guidparameter,integer,character
varying) line 41 at SQL statement SQL state: 42601
Can please someone help me out that what's actually wrong with my function call?
Starting at line 41 (as the error message told you) you got:
SELECT dtCurrDateTime = fnGetDate();
SELECT iCurrDate = fnMC2DateToMC2(dtCurrDateTime);
SELECT iCurrTime = fnMC2DateTimeToMC2(dtCurrDateTime);
I assume you want to set the variables there. But you're doing it wrong. (It looks like you tried to use SQL Server syntax. Is this an attempt to port a function from SQL Server to Postgres? There are also BEGIN ... END blocks for IFs and ELSEs, which are unnecessary (but harmless) in Postgres but needed in SQL Server.)
Either use INTO:
SELECT fnGetDate() INTO dtCurrDateTime;
SELECT fnMC2DateToMC2(dtCurrDateTime) INTO iCurrDate;
SELECT fnMC2DateTimeToMC2(dtCurrDateTime) INTO iCurrTime;
Or, since you're not actually querying a table, simple assignments should work too:
dtCurrDateTime = fnGetDate();
iCurrDate = fnMC2DateToMC2(dtCurrDateTime);
iCurrTime = fnMC2DateTimeToMC2(dtCurrDateTime);
There might be other lines with the same mistake, you should check the whole code.

I need a function

I need to create a function that in cm_customers$rt table to verify to resident clients if the TAX_NUMBER is 13 digits otherwise need show the list to the screen, i was create juste select but i need a function,please help me
select TAX_NUMBER,RESIDENT
from cm_customers$rt
WHERE length (TAX_NUMBER) =13 and resident = 'Y'
;
CREATE OR REPLACE FUNCTION f_tax
RETURN NUMBER
IS
V_tax_number int;
BEGIN
SELECT tax_number
INTO V_tax_number
FROM E_EMP
WHERE LENGTH(tax_number ) < 13
AND residence_type = 'Y';
RETURN V_tax_number;
END;

Postgres while loop really slow

I got this sproc where i get the volume depending on a "FlowVolume" it could be 1, 10, 100. The only way that I found to make this work is the current implementation, but is really slow. The other way is to have intervals in the "Timestamp" it could be every 12 seconds, every 2 mins or every 20 mins intervals.
CREATE OR REPLACE FUNCTION "getBLTPoints"(IN id integer)
RETURNS TABLE(times text, bio text, particles text) AS
$BODY$
DECLARE
currVol real;
currbio integer;
currpart integer;
times timestamp with time zone;
totalvol integer;
profileid integer;
analysisopt integer;
analysisvol integer;
counter integer;
BEGIN
--Getting the right profile to get the line,autosample,analysis volume
select "ProfileID"into profileid from "Samples" where "ID" = id;
--Getting the mode that the system was in when sample was done
select "optBaseVolume" into analysisopt from "Profiles" where "ID" = profileid;
if(analysisopt = 0) then
analysisvol = 1;
elseif(analysisopt = 1) then
analysisvol = 10;
else
analysisvol = 100;
end if;
counter = analysisvol;
--Getting the totalvolume to run it in the while loop until it reaches the totalvolume
select floor("FlowVolume")::integer into totalvol from "Results" where "SampleID" = id order by "FlowVolume" desc limit 1;
WHILE counter <= totalvol LOOP
RETURN QUERY
select extract('epoch' from "Timestamp")::text,"BioAccumulated"::text, "TotalParticlesAccum"::text from
"Results" where "SampleID" = id and "FlowVolume" = counter;
counter = counter + analysisvol;
END LOOP;
END;
using a RETURN QUERY inside any cycle cannot be fast. WHILE cycle is fast as your nested query is fast. But you can use significantly faster technique .. you can generate a counter series by function generate_series, and you can join this series to your "Result" table:
RETURN QUERY SELECT extract('epoch' FROM "Timestamp")::text,
"BioAccumulated"::text,
"TotalParticlesAccum"::text
FROM "Result"
JOIN generate_series(analysisvol, totalvol, analysisvol) g(v)
ON "Result"."FlowVolume" = g.v
WHERE "SampleID" = id;