hey all, trying out honeySQL for XTDB
how can i write the following
user=> INSERT INTO people (_id, name, info)
SELECT _id, name, info
FROM people FOR ALL SYSTEM_TIME
WHERE _id = 6
ORDER BY _system_to DESC
LIMIT 1;
INSERT 0 0
user=> SELECT * FROM people;
_id | info | likes | name
-----+-----------------------------------------------------------------------------------------------+-------------------------------------+------
6 | {"contact":[{"loc":"home","tel":"123"},{"loc":"work","registered":"2024-01-01","tel":"456"}]} | | fred
9 | | ["fishing",3.14,{"nested":"data"}] | bob
(2 rows)
I have tried something like
(execute! conn {:insert-into :test-01
:select [:*]
:from [[:test-01 :for :system-time :all]]
:order-by [[:_system_to :desc]]
:limit 1})
which producted the following
[SELECT * INSERT INTO test_01 FROM test_01 FOR SYSTEM_TIME ALL ORDER BY _system_to DESC LIMIT ? 1]
how can i write it using records, without the need to specify the fields of the entity?hey @itai the output from HoneySQL will need to look more like:
INSERT INTO docs (SELECT *
FROM docs FOR ALL SYSTEM_TIME
WHERE _id = 1
ORDER BY _system_to DESC
LIMIT 1)
https://play.xtdb.com/?version=2.0.0-beta6&type=sql-v2&enc=2&txs=NobwRAzgnhAuCmBbAtLAlo%2BYBcA7ArgDaEA0YsAHhDmAJIByAygKIBKAKgAQPsDynAEwD2AYwicAFAH00AkpxFDCARgCUnAGoBBADIBVZo0nL5AcgBmQoadUBuADq4GLDt3p9Bo8a2YBhXqwAIkYgMgLYnCYKSsoRpgBGAIYATqbyioQATNimnEkAXqYAvrZgRSTgAI748MlQNLDJNWBklNTYdExsXDz8wmKSLDp%2BXABUjpycAGKsvACyngNTAZy6OpyMAJqM7MxzUuy0c8wTnADqABJszJxhnAC8kacBgWycAEKbt9BwSFKwQk4r0YvlOOiOtC4ajKFXIVBoEHghHgIlgnFGnHMySEiEWEFKZB%2BCBQ6EwOAIxCKAF0gAdo you know how can i achieve it? what's the HoneySQL syntax?
(sql/format {:insert-into [[:docs {:select :*
:from [[:docs :for :all :system-time]]
:where [:= :-id 1]
:order-by [[:-system-to :desc]]
:limit 1}]]})
=> ["INSERT INTO DOCS (SELECT * FROM docs FOR ALL SYSTEM TIME WHERE _id = ? ORDER BY _system_to DESC LIMIT ?)" 1 1]Not sure about the nesting of :docs part since it results in DOCS.
Ah, since parentheses don't seem to be needed, just remove the extra [...] around :docs.
great thanks, it worked