pgFormatter icon indicating copy to clipboard operation
pgFormatter copied to clipboard

on conflict do update (& `language` named column)

Open zoriya opened this issue 1 year ago • 4 comments

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).

zoriya avatar Nov 01 '24 13:11 zoriya

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

darold avatar Nov 04 '24 15:11 darold

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;

zoriya avatar Nov 04 '24 17:11 zoriya

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

darold avatar Nov 05 '24 01:11 darold

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.

darold avatar Nov 06 '24 02:11 darold

Commit 025004d fix the last issue.

darold avatar Aug 27 '25 16:08 darold