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

on conflict do update (& language named column) #349

Open
zoriya opened this issue Nov 1, 2024 · 4 comments
Open

on conflict do update (& language named column) #349

zoriya opened this issue Nov 1, 2024 · 4 comments

Comments

@zoriya
Copy link

zoriya commented Nov 1, 2024

I found two issues. First, #150 which seems to occur again.
The second is each time I reference a table named language, the formatter inserts a newline.

Here is my query:

insert into videos(sha, idx, title, language, codec, mime_codec, width, height, is_default, bitrate)
values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
on conflict (sha, idx) do update set
	sha = excluded.sha,
	idx = excluded.idx,
	title = excluded.title,
	language = excluded.language,
	codec = excluded.codec,
	mime_codec = excluded.mime_codec,
	width = excluded.width,
	height = excluded.height,
	is_default = excluded.is_default,
	bitrate = excluded.bitrate;

and it gets formatted like:

insert into videos (sha, idx, title,
    language, codec, mime_codec, width, height, is_default, bitrate)
    values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
on conflict (sha, idx)
    do update set
        sha = excluded.sha, idx = excluded.idx, title = excluded.title,
        language =
        excluded.language, codec = excluded.codec, mime_codec = excluded.mime_codec, width = excluded.width, height = excluded.height, is_default = excluded.is_default, bitrate = excluded.bitrate;

notice how there's a newline before every language.
if I remove each reference to this table, i get this:

insert into videos (sha, idx, title, codec, mime_codec, width, height, is_default, bitrate)
    values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
on conflict (sha, idx)
    do update set
        sha = excluded.sha, idx = excluded.idx, title = excluded.title, codec = excluded.codec, mime_codec = excluded.mime_codec, width = excluded.width, height = excluded.height, is_default = excluded.is_default, bitrate = excluded.bitrate;

and I'd expect every statement in do update set to be on a single line (like in my initial example or what was talked in #150).

@darold
Copy link
Owner

darold commented Nov 4, 2024

Thanks for the report #150 is solves but language is recognize as a plpgsql keyword which should not happen. I'll have a look

@zoriya
Copy link
Author

zoriya commented Nov 4, 2024

are you sure #150 is fixed? i tested both locally and on the website and both gave this sql:

insert into videos (sha, idx, title, codec, mime_codec, width, height, is_default, bitrate)
    values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
on conflict (sha, idx)
    do update set
        sha = excluded.sha, idx = excluded.idx, title = excluded.title, codec = excluded.codec, mime_codec = excluded.mime_codec, width = excluded.width, height = excluded.height, is_default = excluded.is_default, bitrate = excluded.bitrate;

i'd expect it to format like this:

insert into videos(sha, idx, title, codec, mime_codec, width, height, is_default, bitrate)
	values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
on conflict (sha, idx)
	do update set
		sha = excluded.sha,
		idx = excluded.idx,
		title = excluded.title,
		codec = excluded.codec,
		mime_codec = excluded.mime_codec,
		width = excluded.width,
		height = excluded.height,
		is_default = excluded.is_default,
		bitrate = excluded.bitrate;

@darold
Copy link
Owner

darold commented Nov 5, 2024

You are right, I will fix it again in the same commit.

@darold
Copy link
Owner

darold commented Nov 6, 2024

Fixed by commit 5c7463d.

Note that this patch break the form:

...
    DO UPDATE SET
        (a, b, c) = (excluded.a, excluded.b, excluded.c);

I will try to fix this later.

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

No branches or pull requests

2 participants