Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL editor: save query results in variable #4750

Closed
cristianodri opened this issue Dec 7, 2018 · 7 comments
Closed

SQL editor: save query results in variable #4750

cristianodri opened this issue Dec 7, 2018 · 7 comments

Comments

@cristianodri
Copy link

Hello,

I often write insert queries, then copy the inserted id to use it in another insert or update query.
In my opinion it would be useful to have the possibility to assign to named parameters the result of a scalar query.

For example:
@set param1 = insert into test_table (field1, field2) values (value1, value2) returning id;
insert into table2 (field1,field2) values (value1, :param1)

Best regards,
Cristiano

@serge-rider serge-rider changed the title [Feature request] SQL editor: save query results in variable Dec 20, 2018
@serge-rider
Copy link
Member

Good feature.

@serge-rider serge-rider added this to the 5.3.4 milestone Dec 20, 2018
@tati-kru tati-kru modified the milestones: 5.3.4, 5.3.5 Feb 4, 2019
@tati-kru tati-kru modified the milestones: 5.3.5, 6.0.1 Feb 20, 2019
@tati-kru tati-kru modified the milestones: 6.0.1, 6.0.4 Mar 12, 2019
@serge-rider serge-rider modified the milestones: 6.0.4, 6.1.1 May 13, 2019
@serge-rider serge-rider modified the milestones: 6.1.1, 6.1.4 Jul 7, 2019
@tati-kru tati-kru added this to Backlog in DBeaver board Jul 22, 2019
@serge-rider serge-rider modified the milestones: 6.1.4, 6.1.5 Aug 5, 2019
@serge-rider serge-rider modified the milestones: 6.1.5, 6.2.0 Aug 19, 2019
@surpavan
Copy link

surpavan commented Aug 21, 2019

Reference - may be close by: #4337

@serge-rider serge-rider modified the milestones: 6.2.0, 6.2.1 Sep 9, 2019
@serge-rider serge-rider modified the milestones: 6.2.1, 6.2.2 Sep 24, 2019
@serge-rider serge-rider removed this from Backlog in DBeaver board Oct 7, 2019
@serge-rider serge-rider removed this from the 6.2.2 milestone Oct 7, 2019
@drawnfallow
Copy link

Is this feature being dropped? It's been carried over milestone to milestone and now it isn't attached to anything.

@uslss
Copy link
Member

uslss commented Nov 16, 2021

implemented in #11533

@uslss uslss closed this as completed Nov 16, 2021
@cristianodri
Copy link
Author

#11533 does not work for my request #4750 (comment)

@uslss
Copy link
Member

uslss commented Nov 16, 2021

@Barosky works for me (picture below, query ends up with an error due to absence of the mentioned tables, but the variable is set and variable value was copied to query)
image
in case, the feature doesn't work for you, please create a new issue with steps to reproduce.

@cristianodri
Copy link
Author

@uslss this one does not work:

@set xx = INSERT INTO test (valore) VALUES ('test') RETURNING id --valore is a varchar field
SELECT :xx
xx is not set: I think the problem is the string value.

also this one does not work for me:
@set xx = INSERT INTO test (numerico) VALUES (1) RETURNING id --numerico is an int field
SELECT :xx
in this last case, xx is set, but when I execute SELECT :xx I get this error:

Error occurred during SQL query execution

Reason:
SQL Error [42601]: ERRORE: errore di sintassi a o presso "("
  Position: 25

So, by the error my understanding is that :xx does not contain the result of the insert, but the whole statement. IMHO this is not the correct behaviour

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants