Skip to content

Why this function of mine cannot be a custom query? #1523

@lemotran

Description

@lemotran

Why this function of mine cannot be a custom query? Can you please explain for me

create or replace function app.verify_coupon_code(
    coupon_code text,
    order_input app.orders,
    order_lines app.order_lines[]
) returns app.coupons as $$
    with coupons_used_count as (
        select o.coupon_code, count(o.coupon_code)
        from app.orders o
        where o.created_by = current_user_id() and o.coupon_code is not null
        group by o.coupon_code
    ),
    avai_coupons as (
        ....
    )
    select *
    from avai_coupons ac
    where lower(ac.code) = lower(coupon_code);

$$ language sql stable;

if change args to arrays then work

create or replace function app.verify_coupon_code_3(
    coupon_code text,
    order_input app.orders[],
    order_lines app.order_lines[]
) returns app.coupons as $$
    select *
    from app.coupons ac
    where lower(ac.code) = lower(coupon_code)
    fetch first row only;

$$ language sql stable;

Screen Shot 2021-08-30 at 10 14 44

Metadata

Metadata

Assignees

No one assigned

    Labels

    ❔ question😓 cannot-reproduceSomeone has attempted but failed to reproduce this; create an example repo to demonstrate the issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions