We want to rename a table that is used in Metabase in the underlying database. Several dashboards depend on this table. Can we rename the underlying table and then ensure that the dashboards still work?
The quick way
By using a view in Snowflake, you should be able to rename the old table, while still allowing queries on the old name to still work.
https://docs.snowflake.com/en/sql-reference/sql/create-view.html
CREATE [ OR REPLACE ] [ SECURE ] [ RECURSIVE ] VIEW [ IF NOT EXISTS ] <name>
[ ( <column_list> ) ]
[ COPY GRANTS ]
[ COMMENT = '<string_literal>' ]
AS <select_statement>
This would look something like this:
CREATE VIEW old_name AS select * from new_name;
The long way
By querying the report_card table within the Metabase database, you can find the question numbers of all the questions that use the table, and then change the name in them.
SELECT * from report_card where dataset_query like '%old_table%'
You could automatically change the table name, but this would risk accidentally changing names that are similar or other breaking changes.
Related
I have a Collection in MongoDb which I store Transaction Data inside it. but for some reasons, the data is duplicated inside the collection. for example I have 10 Documents of the same transaction. I decided to create unique key based on 4 keys: Transaction_Date, Transaction_Time, Transaction_Trace and Account_ID. but when I tried to create the constraint, the MongoDb gave me an Error because I have thousands of duplicated transactions inside and I can not remove them one by one. How can I Apply this constraint to the database collection? is there any way to remove the duplicated transactions with one query?
Any Suggestion would be Appreciated.
Update: I can group the transactions with this:
db.transactions.aggregate( [
{
$group:
{
_id: {
Account_ID:"$ACCOUNT_ID",
Transaction_Date:"$Transaction_Date",
Transaction_Time:"$Transaction_Time",
Transaction_Trace:"$Transaction_Trace"
},count:{$sum:1}
}
}
] )
this gave me the count of duplicated transactions.
but I do not know how to keep one transaction and remove the others.
I'm using Matillion to load data into Snowflake, both on Azure. When I create tables I specify default values for the columns, I don't like having NULLs in the warehouse.
From what I've read, the Database Query orchestration component in Matillion for Snowflake will put the retrieved data set into an Azure blob and use the Snowflake COPY command to move the data from the blob to the target table.
The result is that NULL values are still there in the target table.
Can someone confirm that the COPY command does some kind of bulk data copy and that the default values are effective only with INSERT statements?
If so I'll just use trap the NULL values at the source.
Thanks.
JFS.
It isn't mentioned in a straight-forward way but the COPY INTO … TABLE statement documentation does specify that it will use the default only for skipped column names (and not in other scenarios):
( col_name [ , col_name ... ] )
[ … ]
Any columns excluded from this column list are populated by their default value
Additionally, the NULL-use behaviour is mentioned for another scenario where data may be missing, making no note of the use of defaults:
ERROR_ON_COLUMN_COUNT_MISMATCH = TRUE | FALSE
[ … ]
If the input file contains records with fewer fields than columns in the table, the non-matching columns in the table are loaded with NULL values.
I have three tables in my table named "users", "role" and "user_meta". And i want to use these tables in my model named "User.php" to save the data. But the problem is that if i associate the other two tables with "users" table then cakephp asked for the plural form of the table. It means i have defined the table name as "role" and "user_meta" then cakephp asking for "roles" and "user_meta".
Now problem is that i cannot change my table name, I have use these table names.
Can anyone help me out to How to save data in the other tables?
Thanks,
Sunil Jindal
The idea is to have one model per table.
What you want to use is Model::$useTable to change the table of the models.
In Sitecore I have created an alias called "bob" for a page.
For most items in Sitecore, the data is saved in the Items table in the database. You can easily see these if you search using the Item ID.
However whenever I search for an alias it returns no results:
select * from Items where ID ='0134A009-5D38-43C1-96C6-33C305543B7B'
Are aliases stored in a different location?
I have tried manually looking through all the tables and also ran a script which should search the whole database. If it is stored there then it looks like it is not in plain text.
Aliases like any other items are stored in the Items table.
You should check if you're looking for the Alias in the proper database. Maybe You're checking core or web database instead of master?
I've created a Bob alias in my env and query below returns 1 row containing alias details:
SELECT
*
FROM
[dbo].[Items]
WHERE
ID = '03275C36-32CE-47F7-AD28-9D5D2649E934'
I am trying to create a view in that view I want to insert a record or update a record based on perticular condition so can we insert or update in SQL view. Can we have insert or update statement in view?
Short answer: Yes. But there are restrictions.
Eg: (taken from http://msdn.microsoft.com/en-us/library/ms180800(v=sql.90).aspx )
Any modifications, including UPDATE, INSERT, and DELETE statements, must reference columns from only one base table.
The columns that are being modified in the view must reference the underlying data in the table columns directly. They cannot be derived in any other way, such as through:
An aggregate function (AVG, COUNT, SUM, MIN, MAX, GROUPING, STDEV, STDEVP, VAR and VARP). 2. A computation; the column cannot be computed from an expression using other columns. Columns formed using set operators (UNION, UNION ALL, CROSSJOIN, EXCEPT, and INTERSECT) amount to a computation and are also not updatable.
The columns that are being modified cannot be affected by GROUP BY, HAVING, or DISTINCT clauses.
TOP cannot be used anywhere in the select_statement of the view when WITH CHECK OPTION is also specified.
Sooo... if it is a relatively straight forward insert or update you're trying to achieve, then it is very possible - but the more complex the query (and the view), the more difficult it becomes.
I'd also offer some advice against doing this if you can - in my opinion it adds an unnecessary layer of complication and (as someone who has had to unravel others queries that use this process) it is a real pain to maintain.
No you cannot have an insert or update statement in a view. Refer to the documentation for CREATE VIEW
CREATE VIEW [ schema_name . ] view_name [ (column [ ,...n ] ) ]
[ WITH <view_attribute> [ ,...n ] ]
AS select_statement
[ WITH CHECK OPTION ] [ ; ]
It enforces that the definition must be a SELECT statement.
It would probably be better to instead use a stored procedure or function that returns a table.