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

Is there some type of support to "virtual" computed column on rethinkdb #6951

Open
calebeaires opened this issue Mar 10, 2021 · 1 comment
Open
Labels
tp:enhancement triaged The issue is reviewed and made a decision on it

Comments

@calebeaires
Copy link

At SQL Server we can create a function that can be linked to a table, then we just retrieve that column name to get computed values.

With a function like this

CREATE FUNCTION [dbo].[ufn_AlbumCount] (@ArtistId int)  
RETURNS smallint
AS  
BEGIN  
    DECLARE @AlbumCount int;
    SELECT @AlbumCount = COUNT(AlbumId)
    FROM Albums
    WHERE ArtistId = @ArtistId; 
    RETURN @AlbumCount;
END;
GO

We add this function to the ref table

ALTER TABLE Artists ADD AlbumCount AS dbo.ufn_AlbumCount(ArtistId);

Then we just list the table that will give us the native fields plus a computed column


select * from Artists
+------------+------------------+--------------+-------------+--------------+
| ArtistId   | ArtistName       | ActiveFrom   | CountryId   | AlbumCount   |
|------------+------------------+--------------+-------------+--------------|
| 1          | Iron Maiden      | 1975-12-25   | 3           | 5            |
| 2          | AC/DC            | 1973-01-11   | 2           | 3            |
| 3          | Allan Holdsworth | 1969-01-01   | 3           | 2            |
| 4          | Buddy Rich       | 1919-01-01   | 6           | 1            |
| 5          | Devin Townsend   | 1993-01-01   | 8           | 3            |
| 6          | Jim Reeves       | 1948-01-01   | 6           | 1            |
| 7          | Tom Jones        | 1963-01-01   | 4           | 3            |
| 8          | Maroon 5         | 1994-01-01   | 6           | 0            |
| 9          | The Script       | 2001-01-01   | 5           | 1            |
| 10         | Lit              | 1988-06-26   | 6           | 0            |
+------------+------------------+--------------+-------------+--------------+


@srh
Copy link
Contributor

srh commented Apr 11, 2021

No, but it would be a good feature idea. Every secondary index that uses a custom function should probably have been a computed column.

@gabor-boros gabor-boros added tp:enhancement triaged The issue is reviewed and made a decision on it labels May 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tp:enhancement triaged The issue is reviewed and made a decision on it
Projects
None yet
Development

No branches or pull requests

3 participants