Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a PostgreSQL equivalent of SELECT @@ROWCOUNT in T-SQL?

Question says it all. Any help with working sample much appreciated.

Thanks.

like image 836
Fung Avatar asked Feb 08 '11 05:02

Fung


People also ask

How do I COUNT records in PostgreSQL?

The basic SQL standard query to count the rows in a table is: SELECT count(*) FROM table_name; This can be rather slow because PostgreSQL has to check visibility for all rows, due to the MVCC model.

How do I COUNT unique values in PostgreSQL?

In this form, the COUNT(DISTINCT column) returns the number of unique non-null values in the column. We often use the COUNT() function with the GROUP BY clause to return the number of items for each group. For example, we can use the COUNT() with the GROUP BY clause to return the number of films in each film category.

How do I select a row in PostgreSQL?

If you want to select data from all the columns of the table, you can use an asterisk ( * ) shorthand instead of specifying all the column names. The select list may also contain expressions or literal values. Second, specify the name of the table from which you want to query data after the FROM keyword.

How do I get Rowcount in SQL?

The SQL COUNT() function returns the number of rows in a table satisfying the criteria specified in the WHERE clause. It sets the number of rows or non NULL column values. COUNT() returns 0 if there were no matching rows.


1 Answers

This command allows retrieval of system status indicators. Each item is a key word identifying a state value to be assigned to the specified variable (which should be of the right data type to receive it). The currently available status items are ROW_COUNT, the number of rows processed by the last SQL command sent down to the SQL engine, and RESULT_OID, the OID of the last row inserted by the most recent SQL command. Note that RESULT_OID is only useful after an INSERT command into a table containing OIDs.

GET DIAGNOSTICS integer_var = ROW_COUNT;

Ref.

like image 103
Mitch Wheat Avatar answered Nov 01 '22 17:11

Mitch Wheat