supabase-community / postgrest-go

Isomorphic Go client for PostgREST. (Now Updating)
https://supabase.io
Apache License 2.0
174 stars 26 forks source link

Insert and Upsert do not work #51

Open princefishthrower opened 3 months ago

princefishthrower commented 3 months ago

Bug report

Describe the bug

As the title states, Insert and Upsert do not work - they fail to create and/or update records respectively.

To Reproduce

Try to call Insert or Upsert on any postgres table using supabase-go. I've tried the following combinations:

s.Client.From("my_table").Insert(bytes, true, "", "minimal", "exact").Execute()
s.Client.From("my_table").Insert(bytes, false, "", "minimal", "exact").Execute()
s.Client.From("my_table").Insert(bytes, true, "", "representation", "exact").Execute()
s.Client.From("my_table").Insert(bytes, false, "", "representation", "exact").Execute()
s.Client.From("my_table").Upsert(bytes, "", "representation", "exact").Execute()
s.Client.From("my_table").Upsert(bytes, "", "minimal", "exact").Execute()
s.Client.From("my_table").Upsert(bytes, "my_primary_key_column", "representation", "exact").Execute()
s.Client.From("my_table").Upsert(bytes, "my_primary_key_column", "minimal", "exact").Execute()

I've tried for when the row exists and when it does not; Upsert and Insert fail to update or create the record respectively. The strangest thing is that no error is reported, and with "representation", I always get an empty array.

Expected behavior

The desired row should be inserted. In the case of already existing by primary key, upserted.

Screenshots

N/A

System information

Additional context

I do notice there are no tests including Insert or Upsert, perhaps adding those would help be a cross check against this bug into the future.

muratmirgun commented 3 months ago

Thanks for the issue first of all! I will check and send the result here asap!

muratmirgun commented 3 months ago

Which postgrest-go version did you use?

dmedora commented 3 months ago

Just noting that Insert works for me, like so:

rowJSON := map[string]string{"column1":"val1", "column2":"val2"}
client.From(mytable).Insert(rowJSON, false, "", "representation", "").Execute()