1

Situation

The output out table has values that come from some one of source tables, source1 or source2. All these tables have unique id and there is another table mix that keeps the relation between these ids.

Problem

Given an update on source1 with ids sId, I'd like to input values into out with new unique newIds and at the same time update mix table with (newId, sId, source1).

Is it incorrect to think that doing two step (below) is slower/less efficient?

Expectation

I'd like to input data into two tables at the same time since they're not dependent and want to know whether any of these fails. If it was my way it'd something like:

SELECT
  s.id as sId, s.value as value, fn_uuid() as newId,'source1' as sourceName,
INTO
  [mix (newId, sId, sourceName), out (newId, value)]
FROM 
  source1 s;

Current approach

SELECT fn_uuid() as newId, id as sId, 'source1' as source INTO mix FROM source1

and then

SELECT m.Id, s.value INTO out FROM source1 s JOIN mix m on s.id = m.sId

assuming that fn_uuid() is defined as

CREATE OR REPLACE FUNCTION public.fn_uuid()
RETURNS characte`r varying AS
' import uuid
 return uuid.uuid1().__str__()
 '
LANGUAGE plpythonu VOLATILE;
Dawid Laszuk
  • 1,773
  • 21
  • 39

0 Answers0