Insert the data from Old table to new table, ID from new table and update for the corresponding row in old table. Most optimized way?


snackie
HOME ยป Databases

I have two table. OLDTABLE and NEWTABLE.
I need to insert some data from oldtable to newtable and the get the ID from new table and update in the oldtable for that corresponding row. the newtable ID has seperate column in oldtable which is null by default.


One way is to get the ID from both table while inserting the data in new table and then later find the data in oldtable and update it. Which is simpler way.


Can anyone suggest some optimized way to do so?


Related to : Insert the data from Old table to new table, ID from new table and update for the corresponding row in old table. Most optimized way?
Insert the data from Old table to new table, ID from new table and update for the corresponding row in old table. Most optimized way?
Databases

I have two table. OLDTABLE and NEWTABLE.
I need to insert some data from oldtable to newtable and the get the ID from new table and update in the oldtable for that corresponding row. the newtable ID has seperate column in oldtable which is null by default.


One way is to get the ID from both table while inserting the data in new table and then later find the data in oldtable and update it. Which is simpler way.


Can anyone suggest some optimized way to do so?


insert data from one table to another table table name genrated runtime without declaring the table fields
Databases

I have two table say table1 and table2 all the columns in both table are same but table2 has some extra column in which i want to insert a some default value and name of table is generated runtime so table name can be changed so i cant declare the field of table.


can not insert row in a table while data redirecting from parent table to child table in trigger(stored procedure)
14/12/2014 2:20 am Databases

I am using postgres version: PostgreSQL 9.2.4 on x86_64-unknown-linux-gnu, compiled by gcc (Debian 4.7.2-5) 4.7.2, 64-bit

Description:

I have one parent table and that parent table has many child tables. I want to redirect the data from parent table to child table (while insertion)

(same As this link: Example Link ) (example of ice cream company)

I did following things...

create table tsttbl1 (id integer, name text);

create table tsttbl1_hour0 (LIKE tsttbl1) INHERITS (tsttbl1);

CREATE OR REPLACE FUNCTION insert_tsttbl1_hourbase() RETURNS TRIGGER
AS $$
BEGIN
    RAISE NOTICE 'Hi...%', NEW;
    execute 'INSERT INTO ' || TG_TABLE_SCHEMA|| '.tsttbl1_hour0 values
'|| NEW;
    -- INSERT INTO tsttbl1_hour0 values (NEW.*)';
    RETURN NULL;
END;
$$ LANGUAGE plpgsql;

create trigger trigger_insert_tsttbl1_hourbase before insert on
tsttbl1 FOR EACH ROW EXECUTE PROCEDURE insert_tsttbl1_hourbase();

Here,

parent table:- tsttbl1

child table:- tsttable1_hour0

Trying to achieve: insert into tsttbl1 (id, name) values (0,'xyz');

should insert data in tsttable1_hour0 instead of tsttbl1;

But When i tried to insert the row, i am getting like this...

ccc=# insert into tsttbl1 (id,name) values (1, 'abc');
LOG:  statement: insert into tsttbl1 (id,name) values (1, 'abc');
NOTICE:  Hi...(1,manan)
ERROR:  column "abc" does not exist
LINE 1: INSERT INTO act1.tsttbl1_hour0 values (1,abc)
                                                 ^
QUERY:  INSERT INTO act1.tsttbl1_hour0 values (1,abc)
CONTEXT:  PL/pgSQL function insert_tsttbl1_hourbase() line 4 at
EXECUTE statement

Additional Information:

-> This data redirection can also be achieved by rule. But for my case, this insertion is frequently, so rule might be costly compare to trigger...

so i want to achieve this by trigger only.

-> if i un comment the line "INSERT INTO tsttbl1_hour0 values (NEW.*)'" .. row is inserted successfully


Creating SQL Trigger (insert or update) which will take data from one table and will put to another database table
Databases

I have got one table with name Links with fields


[PUBLICATION_ID],
[PAGE_ID],
[COMPONENT_ID],
[COMPONENT_TEMPLATE_ID],
[COMPONENT_TEMPLATE_PRIORITY],
[COMPONENT_POSITION],[URL]

in database Tridion_Broker


I want to create one SQL Trigger on insert/update which will take data from "Links" table for fields [PUBLICATION_ID], [URL] and put it to different database (GoogleLinks) and table MyLinks.


EDIT:
My Implementation is as below:


DROP TRIGGER IF EXISTS Update_Google_List;<


HD Wallpapers
3D
3D Abstract
City
Celebrities
Indian Celebrities
Cars
Travel
Girls
Animals Birds
Movies
Sports
Black White
Nature
Planes
Anime
Food Drink
Dreamy Fantasy
Architecture
Games
Space
Holidays
Flowers
Love
Artistic
Baby
Beach
Bikes Motorcycles
Macro
Computers
Vector
Funny
Army
Textures
Brands
Misc
Music
Other
Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © bighow.org All Rights Reserved .