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

table aliases #17

Open
yurykozyrev opened this issue Aug 24, 2017 · 1 comment · May be fixed by #18
Open

table aliases #17

yurykozyrev opened this issue Aug 24, 2017 · 1 comment · May be fixed by #18

Comments

@yurykozyrev
Copy link
Contributor

yurykozyrev commented Aug 24, 2017

I would suggest to introduce table aliases for using them in query.

Problem
E.g.: if we use column like this

pqt.NewColumn("version", pqt.TypeIntegerBig(), pqt.WithNotNull(), pqt.WithDefault("version+1", pqt.EventUpdate)

it will generate the following code in SELECT ... ON CONFLICT ... DO UPDATE SET ...:

INSERT INTO tablename (value, version) VALUES ('data', 0) 
ON CONFLICT (id) DO UPDATE SET value='data', version=version+1
RETURNING data, version

which will cause an error column reference "version" is ambiguous

Suggestion
Add table alias so it produce the code like

INSERT INTO tablename AS alias ... alias.version=version+1
@urakozz urakozz linked a pull request Aug 24, 2017 that will close this issue
@piotrkowalczuk
Copy link
Owner

piotrkowalczuk commented Aug 28, 2017

This is interesting edge case that needs to be addressed. In general aliases are already used across pqt. As an example you can check generateRepositoryFindQuery method in /pqtgo/generator.go.

@yurykozyrev what would be your approach to solve this issue?

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

Successfully merging a pull request may close this issue.

2 participants