How to pass a variable in LIMIT clause in function

Discussion of open issues, suggestions and bugs regarding database management and development tools for PostgreSQL
Post Reply
sandip109
Posts: 1
Joined: Tue 10 Nov 2020 11:19

How to pass a variable in LIMIT clause in function

Post by sandip109 » Tue 10 Nov 2020 11:25

Hello,
I am creating a function.
And I have a requirement to fetch some % of the total number of rows fetch of a selectt statement.
So I have the value in a variable.

I have a simple select statement and in that I want to pass this variable in LIMIT clause.

Something like this: How can I use this v_count in a LIMIT clause ?

Create Function (va varchar,va2 varchar)
.....
...
Begin
select count(*) into v_count
from table1;

select *
from table2
limit v_count;
End;

alexa

Re: How to pass a variable in LIMIT clause in function

Post by alexa » Tue 10 Nov 2020 14:43

We recommend you to refer to dedicated SQL forums on this.

Post Reply