varlen
01/29/2022, 5:22 PMgaryaustin
01/29/2022, 5:23 PMvarlen
01/29/2022, 5:26 PMjaf
01/29/2022, 9:42 PMsql
select 
  sp.name, sp.sku, sp.id, 
  sup.display_name as supplier_name,
  ps.id is not null as is_pre_selected
from 
  source_products sp
left join 
  suppliers sup
on 
  sp.supplier_id = sup.id
left join 
  product_shop ps 
on 
  ps.product_id = sp.id and ps.shop_id = 'a50364d3-f61b-4b02-ad34-07cf7993aa38'
where 
  supplier_id = '157545b6-82b6-43e4-9d7d-f1f61cb49bab' 
limit 
  100
I want to abstract the 'hard-coded' values. The first question is, is that even possible with a view? If I understand views correctly I can append the where clause when doing the actual  query, since it behaves like a normal table. But what about the shop_id in the second on condition? 
If at all possible I'd like to avoid creating a function.jaf
01/29/2022, 9:43 PMjaf
01/30/2022, 6:50 PMsql
create or replace function get_source_products(supplier_id_param uuid, shop_id_param uuid)
returns table (
  id uuid,
  main_sku text,
  name text,
  description text,
  sku text, 
  variation_count int2,
  properties jsonb,
  meta jsonb,
  list_price int4,
  wholesale_price int4,
  size text,
  color text,
  supplier_name text,
  is_pre_selected boolean
) as $$
begin
  return query 
    select 
      sp.id,
      sp.main_sku,
      sp.name,
      sp.description,
      sp.sku, 
      sp.variation_count,
      sp.product_properties,
      sp.product_meta,
      sp.list_price,
      sp.wholesale_price,
      sp.size,
      sp.color,
      sup.display_name,
      ps.id is not null
    from 
      source_products sp
    left join 
      suppliers sup 
    on 
      sp.supplier_id = sup.id
    left join 
      product_shop ps 
    on 
      ps.product_id = sp.id and ps.shop_id = shop_id_param
    where 
      sp.supplier_id = supplier_id_param;
end;
$$ language plpgsql;6ary
01/30/2022, 11:57 PM6ary
01/30/2022, 11:57 PMgaryaustin
01/31/2022, 12:21 AM6ary
01/31/2022, 1:00 AMsylar815
01/31/2022, 11:13 AMJorf
01/31/2022, 9:48 PMcreate or replace function add_rating_count_artist (artistid integer) 
returns void as
$$
  update artists
  set ratings = ratings + 1
  where id = artistid;
$$ 
language sql volatile;
Then in my app I call:
async function addRatingCountToArtist(artistId) {
    const { data, error } = await supabase.rpc( 'add_rating_count_artist', { artistid: artistId })
  }
When I check the db, the ratings value has not changed. FYI, the artistId I'm passing in is a number. table name is artists, id is an int4,  ratings is an int4 . Any ideas? Thank youAlf
02/01/2022, 2:38 AMemail_confirmed_at field in my own profile table whenever a user finishes sign-up and confirmation.garyaustin
02/01/2022, 2:51 AMAlf
02/01/2022, 3:01 AMAlf
02/01/2022, 3:02 AMbegin
  UPDATE public.profile 
  SET confirmed_at = new.confirmed_at 
  WHERE id = new.id;
  return new;
end;margo
02/01/2022, 10:55 AMsilentworks
02/01/2022, 11:14 AMMarc
02/02/2022, 12:27 PMamount of all rows in a table with specific columns (account and tokenId)
my try looks like
create or replace function total_token_offers_by_account(tokenId varchar, account varchar) returns int8 as $$
  select count(amount) from "Offers" where owner = account and tokenId = tokenId
$$ language sql
when I call it via
select total_token_offers_by_account("1", "0x...")
it always throws like column "1" does not exist. Well it should look for column tokenId and then search for the value "1".AmusedGrape
02/03/2022, 12:06 AMsql
CREATE POLICY "Public profiles with minimal data"
ON public.profiles
FOR SELECT USING (
  SELECT id, preferred_name, identity_data - 'email' identity_data, access FROM public.profiles 
);beru
02/03/2022, 3:06 PMRhogaar
02/04/2022, 9:50 AMcreate function push_projectid_to_profile()
returns trigger as $$
begin
  update profiles
  set projects = array_append(projects, new.id)
  where id = new.creator;
  return new;
  end;
$$ language plpgsql security definer;
create trigger on_project_created
  after insert on projects
  for each row execute procedure push_projectid_to_profile();
I received this message from the server error    "function array_append(text[], uuid) does not exist" 
The thing is, array_append should exist according to the doc. Did I do something wrong here?
Thanks!osaxma
02/04/2022, 1:24 PMarray_append(projects, new.id::text)Rhogaar
02/04/2022, 1:31 PMWill Lutz
02/06/2022, 2:03 PMcreate or replace function dummy() 
returns text
language plpgsql volatile
as $$
declare
  new_row text;
begin
  insert into slugs(slug, user_id)
  values('slug-test-val', 'user-id-test-val')
  on conflict(user_id) do update set slug = EXCLUDED.slug returning user_id into new_row;
  return (new_row);
end;
$$;
select * from dummy();Will Lutz
02/06/2022, 2:06 PMosaxma
02/06/2022, 6:10 PMselect * from dummy(); there. In other word, comment out the function or remove it from the editor so you can get an output. Apparently, if you have two statements, you won't get a table result.Jason S
02/08/2022, 3:22 AMgaryaustin
02/08/2022, 3:37 AMJason S
02/08/2022, 3:38 AM