Search
 
SCRIPT & CODE EXAMPLE
 

SQL

postgres trigger insert into another table

CREATE OR REPLACE FUNCTION function_copy() RETURNS TRIGGER AS
$BODY$
BEGIN
    INSERT INTO
        table2(id,name)
        VALUES(new.id,new.name);

           RETURN new;
END;
$BODY$
language plpgsql;
Comment

postgres trigger insert into another table

CREATE TRIGGER trig_copy
     AFTER INSERT ON table1
     FOR EACH ROW
     EXECUTE PROCEDURE function_copy();
Comment

POSTGRES INSERT INTO TABLE VALUE FROM OTHER TABLE

##fetch data from other table with sub-query to insert it into another one

INSERT INTO PUBLIC."MyTable"(conversion_job_id, message, last_status)
VALUES (17, 'test', (SELECT status FROM PUBLIC."OtherTable" WHERE id=17))
RETURNING *
Comment

PREVIOUS NEXT
Code Example
Sql :: snowflake select from stage 
Sql :: sql auto_increment syntax 
Sql :: get initials name in sql 
Sql :: how to write uppercase in sql 
Sql :: add not null constraint sql server 
Sql :: nvl in oracle 
Sql :: update column value in sql 
Sql :: sql server select another database 
Sql :: sqlite show table structure 
Sql :: delete rows from table sql 
Sql :: install mysql 5.7 ubuntu 20.04 
Sql :: sql right join 
Sql :: mql5 datetime get hour 
Sql :: grant all privileges database postgres to user 
Sql :: import mysql database command line linux 
Sql :: oracle sql generate list of days 
Sql :: SQLITE_BUSY: database is locked 
Sql :: database stuck on restoring 
Sql :: order by multiple columns 
Sql :: insert or ignore postgres 
Sql :: mysql expression is not in group by clause 
Sql :: mysql best tutorial for beginners 
Sql :: Access PostgreSQL PSQl with sudo 
Sql :: sql insert into select 
Sql :: import csv to postgresql 
Sql :: how to select all fieldsin a soql query 
Sql :: 1422: Explicit or implicit commit is not allowed in stored function or trigger 
Sql :: postgresql port 5432 not open 
Sql :: mysqldump 1 table only 
Sql :: sql distinct vs unique 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =