I would like to view taskhistory of multiple tasks. I am using the following command which allows to check history of one task
select *
from table(information_schema.task_history(
SCHEDULED_TIME_RANGE_START => dateadd(hours,-10, current_timestamp())
,TASK_NAME => 'one_task'));
I have tried giving wildcard as TASK_NAME => '%mytasks%' but it didnt yield any results.
Taks name parameter is optional and could be ommitted in TASK_HISTORY function call. More roboust filtering could be added in subsequent WHERE clause:
SELECT *
FROM TABLE(INFORMATION_SCHEMA.TASK_HISTORY(
SCHEDULED_TIME_RANGE_START => DATEADD(HOURS,-10,current_timestamp()))) s
WHERE s.name ILIKE '%mytasks%';
Use view from SNOWFLAKE.ACCOUNT.ACCOUNT_USAGE Schema
SELECT * FROM SNOWFLAKE.ACCOUNT_USAGE.TASK_HISTORY;
Related
I have a Snowflake table which gets its data (via COPY INTO) from an S3 bucket. When I tried to run the below statement to check the load status, it didn't give any result.
SELECT * FROM TABLE(INFORMATION_SCHEMA.COPY_HISTORY(TABLE_NAME=>'HourlyTransactionStaging', START_TIME=> DATEADD(DAY, -14, CURRENT_TIMESTAMP())));
Instead, I got this error
Table DBNAME.STAGING.HOURLYTRANSACTIONSTAGING did not exist or was purged.
However, when I tried to run this, it ran and gave me the results as well.
select * from information_schema.load_history
Where
Schema_name = 'STAGING'
AND TABLE_NAME = 'HOURLYTRANSACTIONSTAGING';
I figured out what the issue was. Apparently, TABLE_NAME parameter in the COPY_HISTORY function is case sensitive and I was providing the table name as per the conventions.
HourlyTransactionStaging --> HOURLYTRANSACTIONSTAGING
Glad you figured it out. Also you need to make sure that you're on the correct database / schema before running the query as below:
use schema your_db.schema;
select *
from table(information_schema.copy_history(table_name=>'table_name', start_time=> dateadd(hours, -1, current_timestamp())));
I am trying to fetch result from database table with SELECT * and SUM() function.
The sql query is :
SELECT * ,SUM(msg_send) AS msg_send FROM msg_campaigns
Now how to write this query in cakephp3.
I am trying this :
$this->loadModel('MsgCampaigns');
$SmsDetails = $this->MsgCampaigns->find('all',[
'conditions'=>['YEAR(date_time)'=>date('Y')],
'fields'=>['msg_send'=>'SUM(msg_send)','msg_failed'=>'SUM(msg_failed)']
]);
But I do not know how to use SELECT * . Please help
Check the CakePHP Query Builder on how to use SQL functions and how to select all fields.
$query = $this->MsgCampaigns->find();
$query
->select([
'sum_msg_send' => $query->func()->sum('msg_send'),
'sum_msg_failed' => $query->func()->sum('msg_failed')
])
// passing the table instance to the `select` function, selects all fields
->select($this->MsgCampaigns);
$query->execute();
I want to execute query in my yii2 application. I'm using PostgreSQl. There is a table called list inside the user schema. If I try to build any query it returns 1. My code is here:
$numUsers = Yii::$app->db->createCommand('
SELECT COUNT(*) FROM "user"."list"
')->execute();
Please show me my mistake in the query above.
This is not related to the DB type in Yii2 if you want the result of a single value you should use queryScalar() instead of execute()
$numUsers = Yii::$app->db->createCommand('
SELECT COUNT(*) FROM "user"."list" ')->queryScalar();
I have a table of projects with two of it's columns as 'language' and 'tag'.
After the user gives an input, I want to output all the projects whose language is input or tag is input.
Sql query for above would be this,
Sql query: Select * from TableName where language='input' OR tag='input'
I tried to execute the same in Gql but in vain. What should be the query in Gql to output the data in the above mentioned way.
GQL doesn't have OR, so basically you have to make two separate queries and union results:
Select * from TableName where language='input'
Select * from TableName where tag='input'
You should join results on your app side, Cloud Console doesn't support such things too.
See GQL reference: https://cloud.google.com/datastore/docs/apis/gql/gql_reference
I don't know if is mandatory for you to use GQL, but in case you are able to avoid it, you can use the ndb filter instead.
results = TableName.query(ndb.OR(TableName.language == 'input',
TableName.tag == 'input'))
for result in results:
....your code here...
More information in: https://cloud.google.com/appengine/docs/python/ndb/queries
I have a simple model where I would like to find some count data per date.
I made this find in order to do that:
$statsubscriptions = $this->Nlist->Statsubscription->find('all',
array(
'fields'=>array('Statsubscription.date','Statsubscription.type','COUNT(*) as qs'),
'qroup'=>array('Statsubscription.date','Statsubscription.type'),
'conditions'=>array('Statsubscription.nlist_id'=>$id),
'recursive'=>-1,
)
);
But it does not work. The generated query is the following:
SELECT `Statsubscription`.`date`, `Statsubscription`.`type`, COUNT(*) as qs
FROM `statsubscriptions` AS `Statsubscription`
WHERE `Statsubscription`.`nlist_id` = 1
GROUP BY is completly missing... Instead of the above I would like this query to be generated:
SELECT `Statsubscription`.`date`, `Statsubscription`.`type`, COUNT(`Statsubscription`.`id`) as qs
FROM `statsubscriptions` AS `Statsubscription`
WHERE `Statsubscription`.`nlist_id` = 1
GROUP BY `Statsubscription`.`date`, `Statsubscription`.`type`
How can I achieve this? And what could be the reason of the missing GROUP BY?
You are writing qroup instead of group (that's q instead of g). Which is why it doesn't work.
P.S.: get some sleep...