-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add scalar functions in postgres (#165)
- Implemented only conditional and stringEquals function based on projection function support required for QS(as per attribute service)
- Loading branch information
1 parent
4bf632a
commit 7f4c943
Showing
3 changed files
with
42 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 31 additions & 1 deletion
32
query-service/src/integrationTest/resources/sql/functions.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,31 @@ | ||
CREATE OR REPLACE FUNCTION dateTimeConvert (bigint, bigint) RETURNS bigint AS $$ select ((($1 + $2 - 1)/$2)*$2) $$ LANGUAGE SQL; | ||
CREATE OR REPLACE FUNCTION dateTimeConvert (bigint, bigint) RETURNS bigint AS $$ select ((($1 + $2 - 1)/$2)*$2) $$ LANGUAGE SQL; | ||
|
||
CREATE OR REPLACE FUNCTION conditional (condition text, first text, second text) | ||
RETURNS text | ||
AS $$ | ||
SELECT | ||
CASE WHEN condition IS NOT NULL | ||
THEN CASE WHEN CAST (condition AS BOOLEAN) THEN first ELSE second END | ||
ELSE NULL | ||
END | ||
$$ | ||
LANGUAGE SQL; | ||
|
||
CREATE OR REPLACE FUNCTION stringEquals (str1 text, str2 text) | ||
RETURNS text | ||
AS $$ | ||
SELECT | ||
CASE WHEN str1 IS NULL AND str2 IS NULL | ||
THEN 'true' | ||
ELSE | ||
CASE WHEN str1 IS NULL OR str2 IS NULL | ||
THEN 'false' | ||
ELSE | ||
CASE WHEN str1 = str2 | ||
THEN 'true' | ||
ELSE 'false' | ||
END | ||
END | ||
END | ||
$$ | ||
LANGUAGE SQL; |