I’m trying to drop temporary tables created by Redshift.
I use the following query to find all the temp tables in the cluster:
select name, count(distinct id)
from stv_tbl_perm
where temp = 1
group by 1
The table i'm trying to drop called $stg_inappshourly.
I've tried to drop it in both of the following methods:
drop table $stg_inappshourly
drop table stg_inappshourly
The first one returns a syntax error. The second one drops the actual table.
Any ideas how to drop it?
Solved.
The reason this table kept existing is because its session had an error and it didn't close as expected.
The only way I found to remove this table was rebooting the Redshift instance.
Related
I'm coming from a background in SQL Server where I would create temp tables using the:
select id
into #test
from table A
I've just moved into a PostGresql environment and I was hoping I could do the same, but I'm getting a syntax error. I did a search and it seems like you have to do a Create Table statement.
Is it not possible to easily create temp tables in Postgres?
Postgres supports SELECT INTO, so this should work fine:
SELECT id
INTO TEMP TABLE test
FROM a
You can also use CREATE TABLE AS:
CREATE TEMP TABLE test AS
SELECT id FROM a
This version is generally preferred, as the CREATE statement provides additional options, and can also be used in PL/pgSQL functions (where the SELECT INTO syntax has been hijacked for variable assignment).
Something strange is happening with my new created tables in Postgres, I can add data to them, but I cannot use PgAdmin to edit the any row.
This is my table columns description:
After executing the query to view all table rows this is what I can see:
Save button is disabled to update my table rows. But this is happening only with my new created tables, as you can see, I have other tables where I'm able to edit rows, for example at this table of Users:
Found the problem! That was happening, because I didn't select any of the columns as 'Primary key':
I'm working on HBase 0.98.12-hadoop2 and phoenix-4.7.0
I created table on phoenix to map with existing table on HBase.
After index testing, It failed to drop table with ERROR.
Error: ERROR 1010 (42M01): Not allowed to mutate table. tableName=my_table (state=42M01,code=1010)
To fix this, I tried to set immutable_rows to true but it didn't work.
0: jdbc:phoenix:localhost:2181:/hbase> alter table "my_table" set immutable_rows=false;
16/07/25 17:04:42 WARN query.ConnectionQueryServicesImpl: Attempt to cache older version of my_table: current= 3, new=3
No rows affected (0.041 seconds)
0: jdbc:phoenix:localhost:2181:/hbase> drop table "my_table";
Error: ERROR 1010 (42M01): Not allowed to mutate table. tableName=my_table(state=42M01,code=1010)
How can I drop it? Any advice would be appreciated.
I take a look into SYSTEM.CATALOG and I found something strange.
I don't know why and when it was inserted into there though,
after deleting it I could finally drop the table.
There has to be some kind of reference to the table you are going to drop.
In my case there was a view that was referencing the table, so, first thing was to execute the drop view to delete that reference and after that the drop table command worked.
I have been trying to figure this out the ENTIRE DAY :( ...
I have several stored procedures (in the same database as well as different databases) that do the same thing.
Creates temp table with name X.
Does processing with X.
Drops X.
The problem is that these stored procedures are creating temp tables with the same name. How do I know which temp table to drop once I'm done with the processing if they all have the name and I can't really DROP using "LIKE" because a temp table might be being used by a different stored procedure?
Here's a scenario.
SP1 starts -
Create temp table.
...and before it goes on, this happens:
SP2 is about finish
Drop temp table.
If the above happens, SP1 runs into issues. Such as "temp table does not exist"
How do I bypass this issue?
When I go to drop a temp table, I need to make sure I'm dropping the table related to the stored procedure that created it. Is this even possible?
You are trying to solve a problem you don't have. Just drop the table. If you look in SSMS you will really have unique tables. The SP knows which one to drop.
If SP1 and SP2 were using the same table you would have more problems than just drop.
IF OBJECT_ID(N'tempdb..#Temp', N'U') IS NOT NULL DROP TABLE #Temp
CREATE TABLE #Temp (sID INT PRIMARY KEY CLUSTERED);
-- look in SSMS and you will see #temp appended
-- use #temp
IF OBJECT_ID(N'tempdb..#Temp', N'U') IS NOT NULL DROP TABLE #Temp
In SP not sure you even need to drop. I think it will be dropped automatically.
But if you run the first two lines and look in SSMS you will see that you have your own #TEMP - not a shared #TEMP. Run the last line and you will see it go away.
How to delete all the records in SQL Server 2008?
To delete all records from a table without deleting the table.
DELETE FROM table_name use with care, there is no undo!
To remove a table
DROP TABLE table_name
from a table?
You can use this if you have no foreign keys to other tables
truncate table TableName
or
delete TableName
if you want all tables
sp_msforeachtable 'delete ?'
Use the DELETE statement
Delete From <TableName>
Eg:
Delete from Student;
I can see the that the others answers shown above are right, but I'll make your life easy.
I even created an example for you. I added some rows and want delete them.
You have to right click on the table and as shown in the figure Script Table a> Delete to> New query Editor widows:
Then another window will open with a script. Delete the line of "where", because you want to delete all rows. Then click Execute.
To make sure you did it right right click over the table and click in "Select Top 1000 rows". Then you can see that the query is empty.
If you want to reset your table, you can do
truncate table TableName
truncate needs privileges, and you can't use it if your table has dependents (another tables that have FK of your table,
For one table
truncate table [table name]
For all tables
EXEC sp_MSforeachtable #command1="truncate table ?"
Delete rows in the Results pane if you want to delete records in the database. If you want to delete all of the rows you can use a Delete query.
Delete from Table_name
delete from TableName
isn't a good practice.
Like in Google BigQuery, it don't let to use delete without "where" clause.
use
truncate table TableName
instead
When the table is very large, it's better to delete table itself with drop table TableName and recreate it, if one has create table query; rather than deleting records one by one, using delete from statement because that can be time consuming.
The statement is DELETE FROM YourDatabaseName.SomeTableName; if you are willing to remove all the records with reasonable permission. But you may see errors in the constraints that you defined for your Foreign Keys. So that you need to change your constraints before removing the records otherwise there is a command for MySQL (which may work for others) to ignore the constraints.
SET foreign_key_checks = 0;
Please be aware that this command will disable your foreign keys constrain check, so this can be dangerous for the relationships you created within your schema.