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

Defining a Function in SQL view and executing it leads to empty result (plv8 language) #4873

Closed
activenode opened this issue Jan 8, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@activenode
Copy link
Contributor

Bug report

Describe the bug

When you use the SQL Editor View and define a function via create or replace... to test if a function works properly and then immediately execute the function via SELECT it will say "no rows returned" although this might be completely false. Probably it is somehow only taking the result of the first statement (function definition).

Note: I am using plv8 language (pgsql extension) but I am pretty sure it works with all languages like this since it doesn't look like a language-related problem.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Go to the SQL Editor
  2. Type in something like ():
create or replace function foobar() 
returns smallint as $$

    var rows = plv8.execute(
        'SELECT COUNT(id) as c FROM whatever_table'
    );

    return rows[0].c;
$$ language plv8;

SELECT foobar()
  1. Click RUN to execute the sql

Expected behavior

It should return the row with the count

Actual Behaviour

Returns no rows.

@activenode activenode added the bug Something isn't working label Jan 8, 2022
@burmecia
Copy link
Member

I think that's multi-statement queries, pg-meta hasn't supported it yet, but there is already an issue about it supabase/postgres-meta#143

@activenode
Copy link
Contributor Author

Hey @burmecia . I'd rather close the related issue or rephrase it. Normally an issue should contain proper description which supabase/postgres-meta#143 does not. But yeah, probably related.

@egor-romanov egor-romanov added enhancement New feature or request and removed bug Something isn't working labels Jan 20, 2023
@burmecia
Copy link
Member

This issue has been fixed. For example, run below SQL in SQL Editor,

create or replace function foobar() 
returns smallint as $$

    var rows = plv8.execute(
        'SELECT 42 as c'
    );

    return rows[0].c;
$$ language plv8;

SELECT foobar()

Got result:
image

@activenode
Copy link
Contributor Author

Works.

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

No branches or pull requests

3 participants