Special features of working with PostgreSQL
General recommendations
-
Create triggers, views, and functions using the
DROP … IF EXISTS
expression (if needed, you can use theCASCADE
command), then theCREATE OR REPLACE
expression. Do not use theCREATE OR REPLACE
command alone. -
Use
"public"
instead of the"dbo"
schema. -
Note that system names are case-sensitive. Use quotes (
""
) for names of tables, columns, and other entities. -
Use the
BOOL
type instead of theBIT
type used in Microsoft SQL. You do not have to use theWHERE "boolColumn" = true
expression to match the value of aBOOL
type field. You can use theWHERE "boolColumn"
orWHERE NOT "boolColumn"
expression instead. -
You can use the short form of the
::TEXT
explicit conversion. -
String matching in PostgreSQL is case-sensitive. You can use the
iLIKE
keyword to execute a case-insensitive matching. Note that matching that uses this keyword is slower than matching that uses theUPPER+LIKE
expression. TheUPPER+LIKE
expression has less strict index applicability rules thaniLIKE
. -
You can use the
CREATE CAST
command to cast types if source code has no implicit type casting. Learn more about the type casting: official vendor documentation (PostgreSQL). -
Create a special procedure parameter to store the current recursion level because PostgreSQL recursive procedures do not have a built-in
NESTLEVEL
function. -
Use the
NAME
type in PostgreSQL instead of theSYSNAME
type used in Microsoft SQL. -
Create rules instead of empty
INSTEAD
triggers. For example:CREATE RULE RU_VwAdministrativeObjects AS
ON UPDATE TO "VwAdministrativeObjects"
DO INSTEAD NOTHING; -
Convert
INT
type toBOOL
type explicitly. Implicit conversion ofINT
type toBOOL
type does not work in PostgreSQL if the correspondingCAST
statement is present and theUPDATE
command is executed. -
Use allowed ways to format string literals. Learn more about string literals: official vendor documentation (quote_ident, quote_literal, format) (PostgreSQL).
-
Use the following expression
DECLARE rowsCount BIGINT = 0;
GET DIAGNOSTICS rowsCount = row_count;instead of
@@ROWCOUNT
. -
Use the following expression
EXISTS (
SELECT 1
FROM "SysSSPEntitySchemaAccessList"
WHERE "EntitySchemaUId" = BaseSchema."UId"
) "IsInSSPEntitySchemaAccessList"instead of the following Microsoft SQL expression
(CASE
WHEN EXISTS
(SELECT 1
FROM [SysSSPEntitySchemaAccessList]
WHERE [SysSSPEntitySchemaAccessList].[EntitySchemaUId] = [BaseSchemas].[UId] ) THEN 1
ELSE 0
END) AS [IsInSSPEntitySchemaAccessList]The response field will have a
BOOL
type.
Data type matching
View the Creatio, Microsoft SQL, and PostgreSQL data type matching in the table below.
Type value in the Creatio object Designer | Data type | |
---|---|---|
Microsoft SQL | PostgreSQL | |
BLOB | VARBINARY | BYTEA |
Boolean | BIT | BOOLEAN |
Color | NVARCHAR | CHARACTER VARYING |
CRC | NVARCHAR | CHARACTER VARYING |
Currency | DECIMAL | NUMERIC |
Date | DATE | DATE |
Date/Time | DATETIME2 | TIMESTAMP WITHOUT TIME ZONE |
Decimal (0.00000001) | DECIMAL | NUMERIC |
Decimal (0.0001) | DECIMAL | NUMERIC |
Decimal (0.001) | DECIMAL | NUMERIC |
Decimal (0.01) | DECIMAL | NUMERIC |
Decimal (0.1) | DECIMAL | NUMERIC |
Encrypted string | NVARCHAR | CHARACTER VARYING |
File | VARBINARY | BYTEA |
Image | VARBINARY | BYTEA |
Image Link | UNIQUEIDENTIFIER | UUID |
Integer | INTEGER | INTEGER |
Lookup | UNIQUEIDENTIFIER | UUID |
Text (250 characters) | NVARCHAR(250) | CHARACTER VARYING |
Text (50 characters) | NVARCHAR(50) | CHARACTER VARYING |
Text (500 characters) | NVARCHAR(500) | CHARACTER VARYING |
Time | TIME | TIME WITHOUT TIME ZONE |
Unique identifier | UNIQUEIDENTIFIER | UUID |
Unlimited length text | NVARCHAR(MAX) | TEXT |
See also
Resources
cast types (official PostgreSQL documentation)
quote_ident (official PostgreSQL documentation)
quote_literal (official PostgreSQL documentation)
format (official PostgreSQL documentation)