rdesantis / hauldata

Database Process Automation made easy.
Apache License 2.0
1 stars 0 forks source link

VALUES variable type #121

Closed rdesantis closed 4 years ago

rdesantis commented 4 years ago

Allow variables of type VALUES. They are used as in the following example:

VARIABLES … <values-name> VALUES … ;
…
INSERT INTO <values-name> VALUES (<row-1-value-1-expression>[,<row-1-value-2-expression>... ])[, …];
…
FOR <v1>, <v2>… FROM <values-name>;
…
END FOR

Use the INSERT keyword rather than a regular SET because SET allows setting multiple variables in a comma-separated list, but a VALUES clause itself includes a comma-separated list, which causes a clash of syntax. Also a separate INSERT allows for building a VALUES variable row by row (which has its own danger if misused to build very large row sets). Also need a TRUNCATE task to clear out the row set from a VALUES variable.

To avoid concurrency issues, all expressions must be evaluated at INSERT time rather than being lazily evaluated when is used in a FROM clause.

To be really useful, it must be possible to pass a VALUES variable to a child script.

As an alternative to the TABLE variable type, the VALUES type better fits the precise needs of the anticipated use cases. A more generic DATA variable type, which would be set with an arbitrary FROM clause, would be problematic in that it creates a closure and becomes dependent on context in a way that would work poorly when concurrent tasks or asynchronous processes are involved.

rdesantis commented 4 years ago

Implemented per https://github.com/rdesantis/hauldata/commit/9d7791f3d5d76319a5593c150c3879694737c458. Renamed to TABLE per https://github.com/rdesantis/hauldata/commit/1b69cfff7187392436118b5cb0278eea1c30828b. Can be passed to child script per https://github.com/rdesantis/hauldata/commit/8388884184f73c9d2da7b8b65b2b3b624f79fbd1.