![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I want to be able to update several tables "simultaneously". I have a data entity that is stored accross multiple tables, in a normalised db schema (4NF). |
|
I would like to know how to wrap CRUD (Create, Retrieve, Update and Delete functionality) in transactions, so that when part of the operation fails, the entire transaction is 'rolled back'. |
|
The function should have the following 'prototype' CREATE OR REPLACE FUNCTION insert_library_data(lib_id integer, lib_name varchar, books varchar ) RETURNS integer AS $$ BEGIN -- // If anything goes wrong below, ROLLBACK -- Insert the library data -- parse the books string and get the individual rows -- insert book rows RETURN lib_id + 1; END; $$ LANGUAGE plpgsql; |
#3
| |||
| |||
|
|
I want to be able to update several tables "simultaneously". I have a data entity that is stored accross multiple tables, in a normalised db schema (4NF). |
|
I would like to know how to wrap CRUD (Create, Retrieve, Update and Delete functionality) in transactions, so that when part of the operation fails, the entire transaction is 'rolled back'. |
|
The function should have the following 'prototype' CREATE OR REPLACE FUNCTION insert_library_data(lib_id integer, lib_name varchar, books varchar ) RETURNS integer AS $$ BEGIN -- // If anything goes wrong below, ROLLBACK -- Insert the library data -- parse the books string and get the individual rows -- insert book rows RETURN lib_id + 1; END; $$ LANGUAGE plpgsql; |
#4
| |||
| |||
|
|
I want to be able to update several tables "simultaneously". I have a data entity that is stored accross multiple tables, in a normalised db schema (4NF). |
|
I would like to know how to wrap CRUD (Create, Retrieve, Update and Delete functionality) in transactions, so that when part of the operation fails, the entire transaction is 'rolled back'. |
|
The function should have the following 'prototype' CREATE OR REPLACE FUNCTION insert_library_data(lib_id integer, lib_name varchar, books varchar ) RETURNS integer AS $$ BEGIN -- // If anything goes wrong below, ROLLBACK -- Insert the library data -- parse the books string and get the individual rows -- insert book rows RETURN lib_id + 1; END; $$ LANGUAGE plpgsql; |
#5
| |||
| |||
|
|
I want to be able to update several tables "simultaneously". I have a data entity that is stored accross multiple tables, in a normalised db schema (4NF). |
|
I would like to know how to wrap CRUD (Create, Retrieve, Update and Delete functionality) in transactions, so that when part of the operation fails, the entire transaction is 'rolled back'. |
|
The function should have the following 'prototype' CREATE OR REPLACE FUNCTION insert_library_data(lib_id integer, lib_name varchar, books varchar ) RETURNS integer AS $$ BEGIN -- // If anything goes wrong below, ROLLBACK -- Insert the library data -- parse the books string and get the individual rows -- insert book rows RETURN lib_id + 1; END; $$ LANGUAGE plpgsql; |
#6
| |||
| |||
|
|
I want to be able to update several tables "simultaneously". I have a data entity that is stored accross multiple tables, in a normalised db schema (4NF). |
|
I would like to know how to wrap CRUD (Create, Retrieve, Update and Delete functionality) in transactions, so that when part of the operation fails, the entire transaction is 'rolled back'. |
|
The function should have the following 'prototype' CREATE OR REPLACE FUNCTION insert_library_data(lib_id integer, lib_name varchar, books varchar ) RETURNS integer AS $$ BEGIN -- // If anything goes wrong below, ROLLBACK -- Insert the library data -- parse the books string and get the individual rows -- insert book rows RETURN lib_id + 1; END; $$ LANGUAGE plpgsql; |
#7
| |||
| |||
|
|
I want to be able to update several tables "simultaneously". I have a data entity that is stored accross multiple tables, in a normalised db schema (4NF). |
|
I would like to know how to wrap CRUD (Create, Retrieve, Update and Delete functionality) in transactions, so that when part of the operation fails, the entire transaction is 'rolled back'. |
|
The function should have the following 'prototype' CREATE OR REPLACE FUNCTION insert_library_data(lib_id integer, lib_name varchar, books varchar ) RETURNS integer AS $$ BEGIN -- // If anything goes wrong below, ROLLBACK -- Insert the library data -- parse the books string and get the individual rows -- insert book rows RETURN lib_id + 1; END; $$ LANGUAGE plpgsql; |
#8
| |||
| |||
|
|
I want to be able to update several tables "simultaneously". I have a data entity that is stored accross multiple tables, in a normalised db schema (4NF). |
|
I would like to know how to wrap CRUD (Create, Retrieve, Update and Delete functionality) in transactions, so that when part of the operation fails, the entire transaction is 'rolled back'. |
|
The function should have the following 'prototype' CREATE OR REPLACE FUNCTION insert_library_data(lib_id integer, lib_name varchar, books varchar ) RETURNS integer AS $$ BEGIN -- // If anything goes wrong below, ROLLBACK -- Insert the library data -- parse the books string and get the individual rows -- insert book rows RETURN lib_id + 1; END; $$ LANGUAGE plpgsql; |
#9
| |||
| |||
|
|
I want to be able to update several tables "simultaneously". I have a data entity that is stored accross multiple tables, in a normalised db schema (4NF). |
|
I would like to know how to wrap CRUD (Create, Retrieve, Update and Delete functionality) in transactions, so that when part of the operation fails, the entire transaction is 'rolled back'. |
|
The function should have the following 'prototype' CREATE OR REPLACE FUNCTION insert_library_data(lib_id integer, lib_name varchar, books varchar ) RETURNS integer AS $$ BEGIN -- // If anything goes wrong below, ROLLBACK -- Insert the library data -- parse the books string and get the individual rows -- insert book rows RETURN lib_id + 1; END; $$ LANGUAGE plpgsql; |
#10
| |||
| |||
|
|
begin Ronald Raygun schrieb: I want to be able to update several tables "simultaneously". I have a data entity that is stored accross multiple tables, in a normalised db schema (4NF). Use a TRANSACTION. I would like to know how to wrap CRUD (Create, Retrieve, Update and Delete functionality) in transactions, so that when part of the operation fails, the entire transaction is 'rolled back'. BEGIN; Create ... Select ... Update ... Delete ... Truncate ... ... COMMIT; |
|
If one of these steps failed -> the transaction failed completely. The function should have the following 'prototype' CREATE OR REPLACE FUNCTION insert_library_data(lib_id integer, lib_name varchar, books varchar ) RETURNS integer AS $$ BEGIN -- // If anything goes wrong below, ROLLBACK -- Insert the library data -- parse the books string and get the individual rows -- insert book rows RETURN lib_id + 1; END; $$ LANGUAGE plpgsql; A funktion runs in a own transaction, and yes, you can use a function. But you should use SERIAL instead integer for the ID. Thanks for the info. In the function above, the problem is that I do not |
| end Andreas |
![]() |
| Thread Tools | |
| Display Modes | |
| |