jeffshumphreys / filmcab

A film collector's management system

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create table/row singleton

jeffshumphreys opened this issue · comments

CREATE VIEW myview AS SELECT * FROM mytab;

is very nearly the same thing as

CREATE RULE "_RETURN" AS ON SELECT TO myview DO INSTEAD
if rowcount = 0
SELECT -1
else return value

also rules to block delete and insert of more than row, and

Or update just creates a first row?

So code is (UPDATE active_batch_run_session_running_values SET active_batch_run_session_id = new value (must be new??)

insert is blocked, throws error.

SELECT returns either -1 or the one value there.

It's there!
See sql\build_singleton.sql
Table is simplified.batch_run_session_active_running_values, but use the view simplified.batch_run_session_active_running_values_ext_v or it won't work.

Adding code:

UPDATE simplified.batch_run_session_active_running_values_ext_v SET active_batch_run_session_id  = <new_id>;

to Task _start_new_batch_run_session.ps1.

Then, in script _dot_include_standard_header.ps1, in the function main_for_dot_include_standard_header, after connection established, we run:

SELECT active_batch_run_session_id FROM simplified.batch_run_session_active_running_values_ext_v;

We need a get-sql function that is scalar.

Done, now back to other task.