Snippets

Lucas Possamai GEO-699

Created by Lucas Possamai last modified
WITH -- The first step is to complete the supplied data with actual data from the live table
gsdi_hydrated_rows AS
  ( SELECT gsdi_input_set.gsdi_input_identifier,
           -- preliminary input validation starts. It emits an hstore array with all the failures
NULLIF(-- we check if any of the primary key members is null in the joined table. If it is, this qualifies as a missed match
(CASE WHEN (gsdi_target_table.id IS NULL) THEN ARRAY[CONCAT('"symbol" => "gsdi_no_pk_match", "info" => "Primary key attributes did not match any record in the target table", "details" => "[\"id\"]"')] ELSE '{}' END) , '{}') AS gsdi_validation_failures,
-- case/nullif cascade to translate ASCII SUB into values from target table and CAN into nulls, respectively.
(CASE (gsdi_input_set.id) WHEN E'\x1A' THEN CAST(gsdi_target_table.id AS TEXT) ELSE (NULLIF(gsdi_input_set.id, E'\x18')) END) AS id,
(CASE (gsdi_input_set.mobiuserid) WHEN E'\x1A' THEN CAST(gsdi_target_table.mobiuserid AS TEXT) ELSE (NULLIF(gsdi_input_set.mobiuserid, E'\x18')) END) AS mobiuserid,
(CASE (gsdi_input_set.jobid) WHEN E'\x1A' THEN CAST(gsdi_target_table.jobid AS TEXT) ELSE (NULLIF(gsdi_input_set.jobid, E'\x18')) END) AS jobid,
(CASE (gsdi_input_set.description) WHEN E'\x1A' THEN CAST(gsdi_target_table.description AS TEXT) ELSE (NULLIF(gsdi_input_set.description, E'\x18')) END) AS description,
(CASE (gsdi_input_set.time_start) WHEN E'\x1A' THEN CAST(gsdi_target_table.time_start AS TEXT) ELSE (NULLIF(gsdi_input_set.time_start, E'\x18')) END) AS time_start,
(CASE (gsdi_input_set.note_type) WHEN E'\x1A' THEN CAST(gsdi_target_table.note_type AS TEXT) ELSE (NULLIF(gsdi_input_set.note_type, E'\x18')) END) AS note_type,
(CASE (gsdi_input_set.unit_price) WHEN E'\x1A' THEN CAST(gsdi_target_table.unit_price AS TEXT) ELSE (NULLIF(gsdi_input_set.unit_price, E'\x18')) END) AS unit_price,
(CASE (gsdi_input_set.item_code) WHEN E'\x1A' THEN CAST(gsdi_target_table.item_code AS TEXT) ELSE (NULLIF(gsdi_input_set.item_code, E'\x18')) END) AS item_code,
(CASE (gsdi_input_set.invoiceid) WHEN E'\x1A' THEN CAST(gsdi_target_table.invoiceid AS TEXT) ELSE (NULLIF(gsdi_input_set.invoiceid, E'\x18')) END) AS invoiceid,
(CASE (gsdi_input_set.integration_key) WHEN E'\x1A' THEN CAST(gsdi_target_table.integration_key AS TEXT) ELSE (NULLIF(gsdi_input_set.integration_key, E'\x18')) END) AS integration_key,
(CASE (gsdi_input_set.integration_type) WHEN E'\x1A' THEN CAST(gsdi_target_table.integration_type AS TEXT) ELSE (NULLIF(gsdi_input_set.integration_type, E'\x18')) END) AS integration_type,
(CASE (gsdi_input_set.taskid) WHEN E'\x1A' THEN CAST(gsdi_target_table.taskid AS TEXT) ELSE (NULLIF(gsdi_input_set.taskid, E'\x18')) END) AS taskid,
(CASE (gsdi_input_set.parentid) WHEN E'\x1A' THEN CAST(gsdi_target_table.parentid AS TEXT) ELSE (NULLIF(gsdi_input_set.parentid, E'\x18')) END) AS parentid,
(CASE (gsdi_input_set.pay_txn_id) WHEN E'\x1A' THEN CAST(gsdi_target_table.pay_txn_id AS TEXT) ELSE (NULLIF(gsdi_input_set.pay_txn_id, E'\x18')) END) AS pay_txn_id,
(CASE (gsdi_input_set.pay_status) WHEN E'\x1A' THEN CAST(gsdi_target_table.pay_status AS TEXT) ELSE (NULLIF(gsdi_input_set.pay_status, E'\x18')) END) AS pay_status,
(CASE (gsdi_input_set.n_quote_status) WHEN E'\x1A' THEN CAST(gsdi_target_table.n_quote_status AS TEXT) ELSE (NULLIF(gsdi_input_set.n_quote_status, E'\x18')) END) AS n_quote_status,
(CASE (gsdi_input_set.purchase_order_line_guid) WHEN E'\x1A' THEN CAST(gsdi_target_table.purchase_order_line_guid AS TEXT) ELSE (NULLIF(gsdi_input_set.purchase_order_line_guid, E'\x18')) END) AS purchase_order_line_guid,
(CASE (gsdi_input_set.unit_cost) WHEN E'\x1A' THEN CAST(gsdi_target_table.unit_cost AS TEXT) ELSE (NULLIF(gsdi_input_set.unit_cost, E'\x18')) END) AS unit_cost,
(CASE (gsdi_input_set.unleashed_status) WHEN E'\x1A' THEN CAST(gsdi_target_table.unleashed_status AS TEXT) ELSE (NULLIF(gsdi_input_set.unleashed_status, E'\x18')) END) AS unleashed_status,
(CASE (gsdi_input_set.accounts_payable_key) WHEN E'\x1A' THEN CAST(gsdi_target_table.accounts_payable_key AS TEXT) ELSE (NULLIF(gsdi_input_set.accounts_payable_key, E'\x18')) END) AS accounts_payable_key,
(CASE (gsdi_input_set.accounts_payable_type) WHEN E'\x1A' THEN CAST(gsdi_target_table.accounts_payable_type AS TEXT) ELSE (NULLIF(gsdi_input_set.accounts_payable_type, E'\x18')) END) AS accounts_payable_type,
(CASE (gsdi_input_set.purchase_order_guid) WHEN E'\x1A' THEN CAST(gsdi_target_table.purchase_order_guid AS TEXT) ELSE (NULLIF(gsdi_input_set.purchase_order_guid, E'\x18')) END) AS purchase_order_guid,
(CASE (gsdi_input_set.eventflag) WHEN E'\x1A' THEN CAST(gsdi_target_table.eventflag AS TEXT) ELSE (NULLIF(gsdi_input_set.eventflag, E'\x18')) END) AS eventflag,
(CASE (gsdi_input_set.field_options) WHEN E'\x1A' THEN CAST(gsdi_target_table.field_options AS TEXT) ELSE (NULLIF(gsdi_input_set.field_options, E'\x18')) END) AS field_options,
(CASE (gsdi_input_set.field_type_id) WHEN E'\x1A' THEN CAST(gsdi_target_table.field_type_id AS TEXT) ELSE (NULLIF(gsdi_input_set.field_type_id, E'\x18')) END) AS field_type_id,
(CASE (gsdi_input_set.ts_created) WHEN E'\x1A' THEN CAST(gsdi_target_table.ts_created AS TEXT) ELSE (NULLIF(gsdi_input_set.ts_created, E'\x18')) END) AS ts_created,
(CASE (gsdi_input_set.ts_modified) WHEN E'\x1A' THEN CAST(gsdi_target_table.ts_modified AS TEXT) ELSE (NULLIF(gsdi_input_set.ts_modified, E'\x18')) END) AS ts_modified,
(CASE (gsdi_input_set.created_userid) WHEN E'\x1A' THEN CAST(gsdi_target_table.created_userid AS TEXT) ELSE (NULLIF(gsdi_input_set.created_userid, E'\x18')) END) AS created_userid,
(CASE (gsdi_input_set.modified_userid) WHEN E'\x1A' THEN CAST(gsdi_target_table.modified_userid AS TEXT) ELSE (NULLIF(gsdi_input_set.modified_userid, E'\x18')) END) AS modified_userid,
(CASE (gsdi_input_set.external_id) WHEN E'\x1A' THEN CAST(gsdi_target_table.external_id AS TEXT) ELSE (NULLIF(gsdi_input_set.external_id, E'\x18')) END) AS external_id,
(CASE (gsdi_input_set.job_users_id) WHEN E'\x1A' THEN CAST(gsdi_target_table.job_users_id AS TEXT) ELSE (NULLIF(gsdi_input_set.job_users_id, E'\x18')) END) AS job_users_id,
(CASE (gsdi_input_set.parcels_quantity) WHEN E'\x1A' THEN CAST(gsdi_target_table.parcels_quantity AS TEXT) ELSE (NULLIF(gsdi_input_set.parcels_quantity, E'\x18')) END) AS parcels_quantity,
(CASE (gsdi_input_set.billable_id) WHEN E'\x1A' THEN CAST(gsdi_target_table.billable_id AS TEXT) ELSE (NULLIF(gsdi_input_set.billable_id, E'\x18')) END) AS billable_id,
(CASE (gsdi_input_set.bill_item_id) WHEN E'\x1A' THEN CAST(gsdi_target_table.bill_item_id AS TEXT) ELSE (NULLIF(gsdi_input_set.bill_item_id, E'\x18')) END) AS bill_item_id,
(CASE (gsdi_input_set.bill_id) WHEN E'\x1A' THEN CAST(gsdi_target_table.bill_id AS TEXT) ELSE (NULLIF(gsdi_input_set.bill_id, E'\x18')) END) AS bill_id,
(CASE (gsdi_input_set.invoice_id) WHEN E'\x1A' THEN CAST(gsdi_target_table.invoice_id AS TEXT) ELSE (NULLIF(gsdi_input_set.invoice_id, E'\x18')) END) AS invoice_id
   FROM (
         VALUES ('0',
                 '33962132',
                 '957603',
                 '13450733',
                 'test add charges without quantity on hand',
                 '2016-02-09 22:20:00+00',
                 'time',
                 E'\x1A',
                  'Discount',
                  E'\x1A',
                   E'\x1A',
                    E'\x1A',
                     E'\x1A',
                      E'\x1A',
                       E'\x1A',
                        E'\x1A',
                         '0',
                         E'\x1A',
                          E'\x1A',
                           E'\x1A',
                            E'\x1A',
                             E'\x1A',
                              E'\x1A',
                               E'\x1A',
                                E'\x1A',
                                 E'\x1A',
                                  E'\x1A',
                                   E'\x1A',
                                    E'\x1A',
                                     E'\x1A',
                                      E'\x1A',
                                       '10518157',
                                       E'\x1A',
                                        '13184231',
                                        '7196575',
                                        E'\x1A',
                                         E'\x1A'), ('1',
                                                    '33962133',
                                                    '957603',
                                                    '13450733',
                                                    'Custom charge',
                                                    '2016-02-09 22:20:00+00',
                                                    'time',
                                                    E'\x1A',
                                                     E'\x18',
                                                      E'\x1A',
                                                       E'\x1A',
                                                        E'\x1A',
                                                         E'\x1A',
                                                          E'\x1A',
                                                           E'\x1A',
                                                            E'\x1A',
                                                             '1',
                                                             E'\x1A',
                                                              E'\x1A',
                                                               E'\x1A',
                                                                E'\x1A',
                                                                 E'\x1A',
                                                                  E'\x1A',
                                                                   E'\x1A',
                                                                    E'\x1A',
                                                                     E'\x1A',
                                                                      E'\x1A',
                                                                       E'\x1A',
                                                                        E'\x1A',
                                                                         E'\x1A',
                                                                          E'\x1A',
                                                                           '10518157',
                                                                           E'\x1A',
                                                                            E'\x1A',
                                                                             '7196576',
                                                                             E'\x1A',
                                                                              E'\x1A'), ('2',
                                                                                         '33962135',
                                                                                         '957603',
                                                                                         '13450733',
                                                                                         'test import parts with Quantity on hand',
                                                                                         '2016-02-09 22:20:00+00',
                                                                                         'part',
                                                                                         E'\x1A',
                                                                                          'Consulting',
                                                                                          E'\x1A',
                                                                                           E'\x1A',
                                                                                            E'\x1A',
                                                                                             E'\x1A',
                                                                                              E'\x1A',
                                                                                               E'\x1A',
                                                                                                E'\x1A',
                                                                                                 '1',
                                                                                                 E'\x1A',
                                                                                                  E'\x1A',
                                                                                                   E'\x1A',
                                                                                                    E'\x1A',
                                                                                                     E'\x1A',
                                                                                                      E'\x1A',
                                                                                                       E'\x1A',
                                                                                                        E'\x1A',
                                                                                                         E'\x1A',
                                                                                                          E'\x1A',
                                                                                                           E'\x1A',
                                                                                                            E'\x1A',
                                                                                                             E'\x1A',
                                                                                                              E'\x1A',
                                                                                                               E'\x18',
                                                                                                                E'\x1A',
                                                                                                                 '13184230',
                                                                                                                 '7196578',
                                                                                                                 E'\x1A',
                                                                                                                  E'\x1A'), ('3',
                                                                                                                             '33962136',
                                                                                                                             '957603',
                                                                                                                             '13450733',
                                                                                                                             'test add manual part',
                                                                                                                             '2016-02-09 22:20:00+00',
                                                                                                                             'part',
                                                                                                                             E'\x1A',
                                                                                                                              'manual',
                                                                                                                              E'\x1A',
                                                                                                                               E'\x1A',
                                                                                                                                E'\x1A',
                                                                                                                                 E'\x1A',
                                                                                                                                  E'\x1A',
                                                                                                                                   E'\x1A',
                                                                                                                                    E'\x1A',
                                                                                                                                     '1',
                                                                                                                                     E'\x1A',
                                                                                                                                      E'\x1A',
                                                                                                                                       E'\x1A',
                                                                                                                                        E'\x1A',
                                                                                                                                         E'\x1A',
                                                                                                                                          E'\x1A',
                                                                                                                                           E'\x1A',
                                                                                                                                            E'\x1A',
                                                                                                                                             E'\x1A',
                                                                                                                                              E'\x1A',
                                                                                                                                               E'\x1A',
                                                                                                                                                E'\x1A',
                                                                                                                                                 E'\x1A',
                                                                                                                                                  E'\x1A',
                                                                                                                                                   E'\x18',
                                                                                                                                                    E'\x1A',
                                                                                                                                                     E'\x1A',
                                                                                                                                                      '7196579',
                                                                                                                                                      E'\x1A',
                                                                                                                                                       E'\x1A')) AS gsdi_input_set(gsdi_input_identifier, id, mobiuserid, jobid, description, time_start, note_type, unit_price, item_code, invoiceid, integration_key, integration_type, taskid, parentid, pay_txn_id, pay_status, n_quote_status, purchase_order_line_guid, unit_cost, unleashed_status, accounts_payable_key, accounts_payable_type, purchase_order_guid, eventflag, field_options, field_type_id, ts_created, ts_modified, created_userid, modified_userid, external_id, job_users_id, parcels_quantity, billable_id, bill_item_id, bill_id, invoice_id)
   LEFT JOIN public.ja_notes AS gsdi_target_table ON -- Casting the not-yet validated input value to the target type is unsafe,
-- we have to do the opposite. Please ensure that an index exists on table `public.ja_notes`
-- for the expression `(CAST(gsdi_target_table.id AS TEXT))`
((CAST(gsdi_target_table.id AS TEXT)) = (gsdi_input_set.id)) ),
-- column and domain NULL/NOT NULL compliance. This has to be done after hydration to account for null hydration results targeted at non nullable columns
gsdi_nullability_compliance AS
  (SELECT nci.gsdi_input_identifier,
          NULLIF((CASE WHEN (nci.id IS NULL) THEN ARRAY[CONCAT('"symbol" => "gsdi_notnull:id", "info" => "Attribute `%1$s` or its data domain cannot be null", "details" => "\"id\""')] ELSE '{}' END) || (CASE WHEN (nci.jobid IS NULL) THEN ARRAY[CONCAT('"symbol" => "gsdi_notnull:jobid", "info" => "Attribute `%1$s` or its data domain cannot be null", "details" => "\"jobid\""')] ELSE '{}' END) , '{}') AS gsdi_validation_failures,
          nci.id,
          nci.mobiuserid,
          nci.jobid,
          nci.description,
          nci.time_start,
          nci.note_type,
          nci.unit_price,
          nci.item_code,
          nci.invoiceid,
          nci.integration_key,
          nci.integration_type,
          nci.taskid,
          nci.parentid,
          nci.pay_txn_id,
          nci.pay_status,
          nci.n_quote_status,
          nci.purchase_order_line_guid,
          nci.unit_cost,
          nci.unleashed_status,
          nci.accounts_payable_key,
          nci.accounts_payable_type,
          nci.purchase_order_guid,
          nci.eventflag,
          nci.field_options,
          nci.field_type_id,
          nci.ts_created,
          nci.ts_modified,
          nci.created_userid,
          nci.modified_userid,
          nci.external_id,
          nci.job_users_id,
          nci.parcels_quantity,
          nci.billable_id,
          nci.bill_item_id,
          nci.bill_id,
          nci.invoice_id
   FROM gsdi_hydrated_rows AS nci
   WHERE (nci.gsdi_validation_failures IS NULL)),
-- built-in data types check compliance
 gsdi_native_types_compliance AS
  ( SELECT ntc.gsdi_input_identifier,
           NULLIF(( (CASE WHEN ((ntc.id IS NULL)
                                OR ((CASE WHEN (ntc.id ~ '^[+-]?[0-9]{1,36}$') THEN (CAST(ntc.id AS NUMERIC) BETWEEN -9223372036854775808 AND 9223372036854775807) ELSE FALSE END))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:id", "info" => "Input data for column `%1$s` is not compatible with data type: int8", "details" => "\"id\""')] END) || (CASE WHEN ((ntc.mobiuserid IS NULL)
OR ((CASE WHEN (ntc.mobiuserid ~ '^[+-]?[0-9]{1,36}$') THEN (CAST(ntc.mobiuserid AS NUMERIC) BETWEEN -9223372036854775808 AND 9223372036854775807) ELSE FALSE END))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:mobiuserid", "info" => "Input data for column `%1$s` is not compatible with data type: int8", "details" => "\"mobiuserid\""')] END) || (CASE WHEN ((ntc.jobid IS NULL)
OR ((CASE WHEN (ntc.jobid ~ '^[+-]?[0-9]{1,36}$') THEN (CAST(ntc.jobid AS NUMERIC) BETWEEN -9223372036854775808 AND 9223372036854775807) ELSE FALSE END))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:jobid", "info" => "Input data for column `%1$s` is not compatible with data type: int8", "details" => "\"jobid\""')] END) || (CASE WHEN ((ntc.time_start IS NULL)
OR (util.validate_type_input('pg_catalog', 'timestamptz', ntc.time_start))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:time_start", "info" => "Input data for column `%1$s` is not compatible with data type: timestamptz", "details" => "\"time_start\""')] END) || (CASE WHEN ((ntc.note_type IS NULL)
OR ((ntc.note_type = ANY('{db_quote,note,note_1,note_2,note_3,note_custom,note_default,note_invoice,note_pdf,note_purchase_order,note_quote,note_standard,note_status,parcel,part,payment,pending_payment,quote,time,timer}')))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:note_type", "info" => "Input data for column `%1$s` is not compatible with data type: db_note_type", "details" => "\"note_type\""')] END) || (CASE WHEN ((ntc.unit_price IS NULL)
OR ((ntc.unit_price ~ '^[+-]?((0*[0-9]{1,10}(\.[0-9]{0,2}0*)?)|((0*[0-9]{0,10})?\.[0-9]{1,10}0*))$'))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:unit_price", "info" => "Input data for column `%1$s` is not compatible with data type: numeric(12, 2)", "details" => "\"unit_price\""')] END) || (CASE WHEN ((ntc.item_code IS NULL)
OR ((CHAR_LENGTH(ntc.item_code) <= 200))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:item_code", "info" => "Input data for column `%1$s` is not compatible with data type: varchar(200)", "details" => "\"item_code\""')] END) || (CASE WHEN ((ntc.invoiceid IS NULL)
OR ((CASE WHEN (ntc.invoiceid ~ '^[+-]?[0-9]{1,36}$') THEN (CAST(ntc.invoiceid AS NUMERIC) BETWEEN -2147483648 AND 2147483647) ELSE FALSE END))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:invoiceid", "info" => "Input data for column `%1$s` is not compatible with data type: int4", "details" => "\"invoiceid\""')] END) || (CASE WHEN ((ntc.integration_key IS NULL)
OR ((CHAR_LENGTH(ntc.integration_key) <= 200))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:integration_key", "info" => "Input data for column `%1$s` is not compatible with data type: varchar(200)", "details" => "\"integration_key\""')] END) || (CASE WHEN ((ntc.integration_type IS NULL)
OR ((CHAR_LENGTH(ntc.integration_type) <= 50))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:integration_type", "info" => "Input data for column `%1$s` is not compatible with data type: varchar(50)", "details" => "\"integration_type\""')] END) || (CASE WHEN ((ntc.taskid IS NULL)
OR ((CASE WHEN (ntc.taskid ~ '^[+-]?[0-9]{1,36}$') THEN (CAST(ntc.taskid AS NUMERIC) BETWEEN -2147483648 AND 2147483647) ELSE FALSE END))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:taskid", "info" => "Input data for column `%1$s` is not compatible with data type: int4", "details" => "\"taskid\""')] END) || (CASE WHEN ((ntc.parentid IS NULL)
OR ((CASE WHEN (ntc.parentid ~ '^[+-]?[0-9]{1,36}$') THEN (CAST(ntc.parentid AS NUMERIC) BETWEEN -2147483648 AND 2147483647) ELSE FALSE END))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:parentid", "info" => "Input data for column `%1$s` is not compatible with data type: int4", "details" => "\"parentid\""')] END) || (CASE WHEN ((ntc.pay_txn_id IS NULL)
OR ((CHAR_LENGTH(ntc.pay_txn_id) <= 70))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:pay_txn_id", "info" => "Input data for column `%1$s` is not compatible with data type: varchar(70)", "details" => "\"pay_txn_id\""')] END) || (CASE WHEN ((ntc.pay_status IS NULL)
OR ((CASE WHEN (ntc.pay_status ~ '^[+-]?[0-9]{1,36}$') THEN (CAST(ntc.pay_status AS NUMERIC) BETWEEN -32768 AND 32767) ELSE FALSE END))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:pay_status", "info" => "Input data for column `%1$s` is not compatible with data type: int2", "details" => "\"pay_status\""')] END) || (CASE WHEN ((ntc.n_quote_status IS NULL)
OR ((CASE WHEN (ntc.n_quote_status ~ '^[+-]?[0-9]{1,36}$') THEN (CAST(ntc.n_quote_status AS NUMERIC) BETWEEN -32768 AND 32767) ELSE FALSE END))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:n_quote_status", "info" => "Input data for column `%1$s` is not compatible with data type: int2", "details" => "\"n_quote_status\""')] END) || (CASE WHEN ((ntc.purchase_order_line_guid IS NULL)
OR ((CHAR_LENGTH(ntc.purchase_order_line_guid) <= 40))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:purchase_order_line_guid", "info" => "Input data for column `%1$s` is not compatible with data type: varchar(40)", "details" => "\"purchase_order_line_guid\""')] END) || (CASE WHEN ((ntc.unit_cost IS NULL)
OR ((ntc.unit_cost ~ '^[+-]?((0*[0-9]{1,10}(\.[0-9]{0,2}0*)?)|((0*[0-9]{0,10})?\.[0-9]{1,10}0*))$'))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:unit_cost", "info" => "Input data for column `%1$s` is not compatible with data type: numeric(12, 2)", "details" => "\"unit_cost\""')] END) || (CASE WHEN ((ntc.unleashed_status IS NULL)
OR ((CHAR_LENGTH(ntc.unleashed_status) <= 16))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:unleashed_status", "info" => "Input data for column `%1$s` is not compatible with data type: varchar(16)", "details" => "\"unleashed_status\""')] END) || (CASE WHEN ((ntc.accounts_payable_key IS NULL)
OR ((CHAR_LENGTH(ntc.accounts_payable_key) <= 50))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:accounts_payable_key", "info" => "Input data for column `%1$s` is not compatible with data type: varchar(50)", "details" => "\"accounts_payable_key\""')] END) || (CASE WHEN ((ntc.accounts_payable_type IS NULL)
OR ((CHAR_LENGTH(ntc.accounts_payable_type) <= 20))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:accounts_payable_type", "info" => "Input data for column `%1$s` is not compatible with data type: varchar(20)", "details" => "\"accounts_payable_type\""')] END) || (CASE WHEN ((ntc.purchase_order_guid IS NULL)
OR ((CHAR_LENGTH(ntc.purchase_order_guid) <= 40))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:purchase_order_guid", "info" => "Input data for column `%1$s` is not compatible with data type: varchar(40)", "details" => "\"purchase_order_guid\""')] END) || (CASE WHEN ((ntc.eventflag IS NULL)
OR ((CASE WHEN (ntc.eventflag ~ '^[+-]?[0-9]{1,36}$') THEN (CAST(ntc.eventflag AS NUMERIC) BETWEEN -2147483648 AND 2147483647) ELSE FALSE END))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:eventflag", "info" => "Input data for column `%1$s` is not compatible with data type: int4", "details" => "\"eventflag\""')] END) || (CASE WHEN ((ntc.field_options IS NULL)
OR (util.validate_type_input('pg_catalog', '_int8', ntc.field_options))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:field_options", "info" => "Input data for column `%1$s` is not compatible with data type: _int8", "details" => "\"field_options\""')] END) || (CASE WHEN ((ntc.field_type_id IS NULL)
OR ((CASE WHEN (ntc.field_type_id ~ '^[+-]?[0-9]{1,36}$') THEN (CAST(ntc.field_type_id AS NUMERIC) BETWEEN -9223372036854775808 AND 9223372036854775807) ELSE FALSE END))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:field_type_id", "info" => "Input data for column `%1$s` is not compatible with data type: int8", "details" => "\"field_type_id\""')] END) || (CASE WHEN ((ntc.ts_created IS NULL)
OR (util.validate_type_input('pg_catalog', 'timestamptz', ntc.ts_created))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:ts_created", "info" => "Input data for column `%1$s` is not compatible with data type: timestamptz", "details" => "\"ts_created\""')] END) || (CASE WHEN ((ntc.ts_modified IS NULL)
OR (util.validate_type_input('pg_catalog', 'timestamptz', ntc.ts_modified))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:ts_modified", "info" => "Input data for column `%1$s` is not compatible with data type: timestamptz", "details" => "\"ts_modified\""')] END) || (CASE WHEN ((ntc.created_userid IS NULL)
OR ((CASE WHEN (ntc.created_userid ~ '^[+-]?[0-9]{1,36}$') THEN (CAST(ntc.created_userid AS NUMERIC) BETWEEN -2147483648 AND 2147483647) ELSE FALSE END))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:created_userid", "info" => "Input data for column `%1$s` is not compatible with data type: int4", "details" => "\"created_userid\""')] END) || (CASE WHEN ((ntc.modified_userid IS NULL)
OR ((CASE WHEN (ntc.modified_userid ~ '^[+-]?[0-9]{1,36}$') THEN (CAST(ntc.modified_userid AS NUMERIC) BETWEEN -2147483648 AND 2147483647) ELSE FALSE END))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:modified_userid", "info" => "Input data for column `%1$s` is not compatible with data type: int4", "details" => "\"modified_userid\""')] END) || (CASE WHEN ((ntc.external_id IS NULL)
OR (util.validate_type_input('pg_catalog', 'uuid', ntc.external_id))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:external_id", "info" => "Input data for column `%1$s` is not compatible with data type: uuid", "details" => "\"external_id\""')] END) || (CASE WHEN ((ntc.job_users_id IS NULL)
OR ((CASE WHEN (ntc.job_users_id ~ '^[+-]?[0-9]{1,36}$') THEN (CAST(ntc.job_users_id AS NUMERIC) BETWEEN -2147483648 AND 2147483647) ELSE FALSE END))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:job_users_id", "info" => "Input data for column `%1$s` is not compatible with data type: int4", "details" => "\"job_users_id\""')] END) || (CASE WHEN ((ntc.parcels_quantity IS NULL)
OR ((ntc.parcels_quantity ~ '^[+-]?((0*[0-9]{1,12}(\.[0-9]{0,4}0*)?)|((0*[0-9]{0,12})?\.[0-9]{1,12}0*))$'))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:parcels_quantity", "info" => "Input data for column `%1$s` is not compatible with data type: numeric(16, 4)", "details" => "\"parcels_quantity\""')] END) || (CASE WHEN ((ntc.billable_id IS NULL)
OR ((CASE WHEN (ntc.billable_id ~ '^[+-]?[0-9]{1,36}$') THEN (CAST(ntc.billable_id AS NUMERIC) BETWEEN -9223372036854775808 AND 9223372036854775807) ELSE FALSE END))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:billable_id", "info" => "Input data for column `%1$s` is not compatible with data type: int8", "details" => "\"billable_id\""')] END) || (CASE WHEN ((ntc.bill_item_id IS NULL)
OR ((CASE WHEN (ntc.bill_item_id ~ '^[+-]?[0-9]{1,36}$') THEN (CAST(ntc.bill_item_id AS NUMERIC) BETWEEN -9223372036854775808 AND 9223372036854775807) ELSE FALSE END))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:bill_item_id", "info" => "Input data for column `%1$s` is not compatible with data type: int8", "details" => "\"bill_item_id\""')] END) || (CASE WHEN ((ntc.bill_id IS NULL)
OR ((CASE WHEN (ntc.bill_id ~ '^[+-]?[0-9]{1,36}$') THEN (CAST(ntc.bill_id AS NUMERIC) BETWEEN -9223372036854775808 AND 9223372036854775807) ELSE FALSE END))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:bill_id", "info" => "Input data for column `%1$s` is not compatible with data type: int8", "details" => "\"bill_id\""')] END) || (CASE WHEN ((ntc.invoice_id IS NULL)
OR ((CASE WHEN (ntc.invoice_id ~ '^[+-]?[0-9]{1,36}$') THEN (CAST(ntc.invoice_id AS NUMERIC) BETWEEN -9223372036854775808 AND 9223372036854775807) ELSE FALSE END))) THEN '{}' ELSE ARRAY[CONCAT('"symbol" => "gsdi_type:invoice_id", "info" => "Input data for column `%1$s` is not compatible with data type: int8", "details" => "\"invoice_id\""')] END) ), '{}') AS gsdi_validation_failures,
           ntc.id,
           ntc.mobiuserid,
           ntc.jobid,
           ntc.description,
           ntc.time_start,
           ntc.note_type,
           ntc.unit_price,
           ntc.item_code,
           ntc.invoiceid,
           ntc.integration_key,
           ntc.integration_type,
           ntc.taskid,
           ntc.parentid,
           ntc.pay_txn_id,
           ntc.pay_status,
           ntc.n_quote_status,
           ntc.purchase_order_line_guid,
           ntc.unit_cost,
           ntc.unleashed_status,
           ntc.accounts_payable_key,
           ntc.accounts_payable_type,
           ntc.purchase_order_guid,
           ntc.eventflag,
           ntc.field_options,
           ntc.field_type_id,
           ntc.ts_created,
           ntc.ts_modified,
           ntc.created_userid,
           ntc.modified_userid,
           ntc.external_id,
           ntc.job_users_id,
           ntc.parcels_quantity,
           ntc.billable_id,
           ntc.bill_item_id,
           ntc.bill_id,
           ntc.invoice_id
   FROM gsdi_nullability_compliance AS ntc
WHERE (ntc.gsdi_validation_failures IS NULL)),

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.