I would like to create a function returning the number of records that an SQL expression passed as parameter can generate. Can anyone put me on the right path?
Postgresql function returning number of records
176 Views Asked by Jacopo Russo At
2
There are 2 best solutions below
0
Hitobat
On
Your function should return a SETOF some (record) type.
You then use the RETURN NEXT syntax to return each row.
See the example in the doc page for this. https://www.postgresql.org/docs/current/static/plpgsql-control-structures.html#id-1.8.8.8.3.4
Related Questions in POSTGRESQL
- Only the first SQL script gets executed inside Docker Postgres container
- Compare fields in two tables
- Hibernate ClobJdbcType bindings: what are the diferences?
- Postgres && statement Error in Mybatis Mapper?
- Can this query be optimized? (Choosing a random row to insert, that excludes previously inserted Rows)
- Connection terminated unexpectedly while performing multi row insert using pg-promise
- Processing multiple forms in nodejs and postgresql
- How to copy data from SQLite to postgreSQL?
- PGAdmin4 configured behind a reverse proxy but unable to connect to Postgresql server
- Updates to pgsodium encrypted values don't use specified key_id
- Connecting to Postgres running in a Docker container using psql
- Can't connect to local postgresql server from my docker container
- Django Arrayfield migration to cloud sql (Postgresql) not creating the column
- Get list of matching keywords for each post
- docker-compose can't reset postgresql database
Related Questions in FUNCTION
- Dynamic array of structures in C++/ cannot fill a dynamic array of doubles in structure from dynamic array of structures
- Function is returning undefined but should be returning a matched object from array in JavaScript
- How do you import functions from one page to another in Jetpack Compose?
- Adding Modules to a Namespace using IIFE
- How to convert mathematical expression to lambda function in C++?
- Custom Bash functions & custom statements - Need some advice
- Why my code is working on everything except one instance?
- Getting a function to call an equation
- Create Symbolic Function from Double Vector MATLAB
- Recursive calls to function passed as a parameter of another method via Consumer interface
- How can I replace a word in SQL but only if it is the last word in the string for a scalar-valued function?
- iterating through raster bands to perform calculation
- How to make this sensor keep taking readings once its when_in_range function has been activated?
- TypeError: indice_delete() takes 0 positional arguments but 3 were given
- How to modify HTML in WordPress core file
Related Questions in PLPGSQL
- How to change column names returned from a function?
- How can I automatically delete row after set time by trigger?
- Function takes significantly longer than specified timeout
- PostgreSQL Query - Solution
- Pass a bounded cursor to a function
- How to pass int2 parameter to a stored function?
- How to print out a datetime stamp info in a plpgSQL using "raise info" function for debugging purpose in Redshift environment
- cannot insert an record into a table inside a LOOP statement with pgplsql (Redshift environment)
- Locking rows behaviour for a temporary table in a PLPGSQL function
- How to show what privileges a user has on a database in Postgres database?
- Trouble Returning The Count of Days Past Due
- Syntax error near 'WHEN place.price > 3000 THEN' in PostgreSQL function
- Postgresql: resolve a one-to-many relationship and delete given tuples, all in one query
- Postgresql equivalent of SQL Server query
- PostgreSQL stored procedure to get an employee by input ID from a joined table
Related Questions in POSTGRESQL-9.4
- Compare fields in two tables
- Compare fields Where One is Similar to Part of Another in Postgres sql
- postgresql one line bash command to remove other session using the database
- How to unnest and order an array
- Variable with Array of objects in Postgres
- Need help configuring PostgreSQL connection to behave like MySQL: Connect to server without auto-selecting default database
- Postgres 9.4 Geo Lookup with IPV6 INET
- I am using pgAdmin 4, PostgreSQL 16, Windows 10. Whenever I try to login into pgAdmin for postgres user, I get can Connection TImeout Error
- How to pass params in function at for in select loop end loop
- How to execute select which stored cell in table
- PostgreSQL - Find corresponding table of a LOB
- No procedure matches the given name and argument types. You might need to add explicit type casts. POSTGRESQL
- Dynamic column names in the Postgres query
- I am confused with PostgresQL/Timescale indexing
- how to insert multiple commands into a prepared statement
Related Questions in RECORD-COUNT
- How do I send a record count of a flat file in an email in SSIS
- How to display the count of records in a file?
- c# datatable row count returns 1 for empty table
- Access VBA Subform Dynamic SQL Parent Form Count Slow
- how to read record count while unloading from redshift to s3 in airflow
- Postgresql function returning number of records
- ColdFusion RecordCount as multiple conditional
- VBA If/Then based on Record Count
- ExecNonQuery SQL
- Access VBA Filter RecordCount not properly updating value
- VBA - ADODB.Connection - Using parameters and retrieving records affected count
- RecordCount Property not working
- How to get FireDAC record count when SetRange active
- Is it possible to use RecordCount with Criteria
- Recordcount returns value of -1
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
In plain SQL you can get the number of returned rows using a derived table (placing the query in a subquery in the
FROMclause) like this:Do the same in a plpgsql function. You need a dynamic command as the function should work for any valid SQL query:
Example: