Special features of working with PostgreSQL
General recommendations
-
Create triggers, views, and functions using the
DROP … IF EXISTSexpression (if needed, you can use theCASCADEcommand), then theCREATE OR REPLACEexpression. Do not use theCREATE OR REPLACEcommand 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
BOOLtype instead of theBITtype used in Microsoft SQL. You do not have to use theWHERE "boolColumn" = trueexpression to match the value of aBOOLtype field. You can use theWHERE "boolColumn"orWHERE NOT "boolColumn"expression instead. -
You can use the short form of the
::TEXTexplicit conversion. -
String matching in PostgreSQL is case-sensitive. You can use the
iLIKEkeyword to execute a case-insensitive matching. Note that matching that uses this keyword is slower than matching that uses theUPPER+LIKEexpression. TheUPPER+LIKEexpression has less strict index applicability rules thaniLIKE. -
You can use the
CREATE CASTcommand 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
NESTLEVELfunction. -
Use the
NAMEtype in PostgreSQL instead of theSYSNAMEtype used in Microsoft SQL. -
Create rules instead of empty
INSTEADtriggers. For example:CREATE RULE RU_VwAdministrativeObjects AS
ON UPDATE TO "VwAdministrativeObjects"
DO INSTEAD NOTHING; -
Convert
INTtype toBOOLtype explicitly. Implicit conversion ofINTtype toBOOLtype does not work in PostgreSQL if the correspondingCASTstatement is present and theUPDATEcommand 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
BOOLtype.
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)