I have a requirement that I need to store a list of parameters. The parameters will be input as a csv file. They will be inserted into a table if not already existing. I have got a suggestion that I can import this data into a volatile table and use a sql query like:
insert into table permvariables
select * from tempvariables
minus
select * from permvariables;
Where tempvariables is my volatile table and permvariables is my permanent table. Will this solution work? Is there a better way to do it?
Instead of MINUS simply use a
MERGE INTO permvariables AS tgt
USING tempvariables AS src
ON tgt.pk_column(s) = src.pk_column(s)
WHEN NOT MATCHED INSERT VALUES (src.pk_column(s), src.cola, ...)
Related
I created a persistent table temp and a temporary table temp, that is, both have the same name. How can I use select/update/insert specifically to the persistent or the temporary table? How can I differ between them?
MariaDB Tutorial says:
Note − Temporary tables are permitted to have the same name as an existing non-temporary table because MariaDB views it as a difference reference.
So, I suppose it should be possible to refer to one of these tables. This question is related to this question I posed in SO, but goes one step back.
In case a temporary table has the same name as an existing non temporary table the temporary table will shadow the name of a non temporary table.
That means in a SQL statement you will not be able to reference the non temporary table.
A work around would be, to create a view on a non temporary table before creating the temporary table, since the view internally keeps the reference to the non temporary table:
CREATE TABLE t1 (a VARCHAR(100));
INSERT INTO t1 VALUES ("foo");
CREATE VIEW v_t1 AS SELECT a FROM t1;
CREATE TEMPORARY TABLE t1 (b VARCHAR(100));
INSERT INTO t1 VALUES ("bar");
SELECT * FROM v_t1;
SELECT * FROM t1;
I want to save the results of my sqlite query in a new sqlite file. in other words, I want to have a new sqlite database with the data which resulted from my query on my previous data set.
All I have found on the internet was how to export the query results to csv or sql. but I want my new data set to be sqlite.
Also, is there any way to save the query results on the same data set (like what we do in excel)? Thank you!
You can ATTACH another database file to an existing connection and create or insert data into a table in that other database.
Something like:
ATTACH DATABASE 'other.db' AS other;
CREATE TABLE other.foo AS SELECT * FROM main.foo; -- create and populate a table
INSERT INTO other.bar SELECT * FROM main.foo; -- insert into an existing table
DETACH other;
I'm coming from SQL Server enviroment where you can declare a temp table with #table, but as I've read you can't do this in oracle.
I want get a value for 500.000 hardcoded id's from a table, but as the IN clause has a limit of 1000 I need to find another way. Is the best way to create a temporary table and insert the hardcoded values and then join the other table which contains the values I need ?
My client (toad) has autocommit set to off and I dont want to commit anything, I want it to be session-based so when I close the database client I want the temporary table do disappear. Is the code below the right way to do in oracle?
CREATE GLOBAL TEMPORARY TABLE Test(HardcodedId number(10))
ON COMMIT DELETE ROWS;
I've also tried to use inner join and in the join select the hardcoded values from dual, but this creates a column for each value and i'm not able to use a reference to join with. Is it possible to insert all values into a single column in dual?
You can use some thing like this (500 union all)
select * from (
select '1' from dual
union all
select '2' from dual
...) q
Then you can join this with other tables.
For your situation, I would use a GTT (global temporary table) - which you have already researched by the looks.
The advantage of a GTT is that it's a permanent object (so no need to constantly create and drop it) and the data "stored" in it is on a session basis.
I want create table from another table with constraint?
I used this query "create table destination as select * from source;" fro table creation.
But its copy only the column name in table without column constraint.
There is a special table named sqlite_master, holding the full CREATE TABLE statement for each table (it's modified as appropriate during ALTER TABLE).
I would make my application retrieve that CREATE TABLE statement:
SELECT sql FROM sqlite_master WHERE type='table' AND name='source';
Then I would replace the table name right after CREATE TABLE tokens, and execute the result as a new sqlite query.
I don't think that it's possible to do in sqlite's pure SQL without extensions.
In my Informatica mapping, I need to do the following activities:
creating 'A' volatile table
inserting records into 'A' table, from 'B' normal table
again I want to insert records into 'C' normal table using 'A' volatile table.
If my question is not clear, just post your comments and I will try to clarify it.
Do you have any logic to impliment after creating the volatile table? what kind of logic(Simple/Complex)? Based on my understanding, here is what you can do. Let me know if you are looking for something else.
You can do this in 2 ways.
create a Stored proc which creates volatile table based on other Multiset table, Impliment logic (If any ) then push it over to Other Multiset table (C)
Read from B, Use SQL transformation to create Volatile table, and then insert to Volatile table
use volatile table as source and use rest of the transformations and then to Table C.