Postgresql: ERROR: syntax error at or near "DO" - postgresql

I am using the below query to perform upsert operation against posstgres db. But i get error "syntax error at or near do". I suppose it is do with line ON CONFLICT ((message_payload-->'jsonContent'->>'message_id'))
Here i am trying to check for identity based on json parameter key messageId. Can some one help me by mentioning the missing info i have.
INSERT INTO public.error_message(
id, created_by, created_dt, modified_by, modified_dt, attempt, message_headers, message_main_topic, message_payload, message_status, message_status_code)
VALUES (51, null, null, null, null, 1, '{
"jsonContent": {
"content-length": "1635",
"message_status_code": "417",
"cookie": "JSESSIONID=279AF4C174E6192BDAB11A067768BBD5",
"postman-token": "f0f33e86-498f-452a-aaf6-18eb84dc5907",
"kafka_timestampType": "CREATE_TIME",
"message_id": "21",
"kafka_receivedMessageKey": "null",
"kafka_receivedTopic": "error-topic",
"accept": "*/*",
"kafka_offset": "33",
"kafka_consumer": "org.apache.kafka.clients.consumer.KafkaConsumer#5091bb5f",
"host": "localhost:8082",
"content-type": "application/json",
"connection": "keep-alive",
"cache-control": "no-cache",
"kafka_receivedPartitionId": "0",
"kafka_receivedTimestamp": "1552305428711",
"accept-encoding": "gzip, deflate",
"message_main_topic": "ldarsQCustomStatistics.1",
"user-agent": "PostmanRuntime/7.6.1"
}
}', ‘abcd.1’, '{
"jsonContent": {
"messageTime": 16772223422,
"messageRev": 9,
"businessId": "DB",
"messageId": "55",
"deviceId": "DB_1234_SMM",
"assetType": "Locomotive",
"messageType": "thirdparty-timeseries",
"assetId": "DB_1234",
"appId": "ThirdPartyApp",
}
}', 1, 201)
ON CONFLICT ((message_payload-->'jsonContent'->>'message_id'))
DO UPDATE SET attempt=attempt+1

Related

I have a problem setting up a RESTAPI call in Azure Data Factory

I am trying to create a POST to an REST-API but I get this output (Caught by an Logic Apps HTTP grab):
{
"headers": {
! "Connection": "Keep-Alive",
"Accept": "application/json",
"Accept-Encoding": "gzip,deflate",
! "Host": "prod-187.westeurope.logic.azure.com:443",
"User-Agent": "azure-data-factory/2.0",
"Content-Length": "55",
! "Content-Type": "application/json",
"Content-Encoding": "UTF-8"
},
"body": {
"$content-encoding": "UTF-8",
"$content-type": "application/json",
"$content": "eyJuYW1lIjoiSmVzcGVyIEIuIEhhbnNlbiIsInNhbGFyeSI6IjEyMzQ1IiwiYWdlIjoiMzQifQ=="
}
}
I would have expected this:
{
"headers": {
"Accept": "application/json",
"Accept-Encoding": "deflate,gzip",
"Host": "prod-187.westeurope.logic.azure.com",
"User-Agent": "Mozilla/5.0,(Windows NT 10.0; Win64; x64),AppleWebKit/537.36,(KHTML, like Gecko),Chrome/103.0.5060.134,Safari/537.36,Edg/103.0.1264.71",
"X-Real-IP": "212.237.135.241",
"Content-Length": "42",
"Content-Type": "application/json"
},
"body": {
"name": "Jesper B. Hansen",
"salary": "12345",
"age": "34"
}
}
Why is the output scrambled?
I tried using a REST Service on a sink, and also tried it with an externalCall no real difference...
I must say, I am new at ADF, but I hope you have some good help for me.

Getting invalid_payment response from uber with 400 status code;using rest API

I am using REST API to book and uber ride using: https://api.uber.com/v1.2/requests .
It's not working with payment methods other than Cash.
I am getting 400 with code:invalid_payment
Can someone please help me out;
I am able to make payment using cash & Paytm for Indian locations.
I am not able to make payment using cash for US locations.
I am not able to make payment using the card for Indian & US locations.
When I add a new card via the Uber app and try to book a cab in the uber using the card it works; When I try to use the same card using my app it shows error. After this when I try to book a cab using the uber app; it doesn't work.
This the the response I am getting from Uber:
{
"data": {
"meta": {},
"errors": [
{
"status": 400,
"code": "invalid_payment",
"title": "The rider's payment method is invalid and they must update their billing info."
}
]
},
"status": 400,
"headers": {
"server": "nginx",
"strict-transport-security": "max-age=604800",
"x-frame-options": "SAMEORIGIN",
"content-type": "application/json",
"content-geo-system": "wgs-84",
"date": "Fri, 05 Apr 2019 06:28:50 GMT",
"x-content-type-options": "nosniff",
"content-length": "151",
"cache-control": "max-age=0",
"connection": "keep-alive",
"x-xss-protection": "1; mode=block"
},
"config": {
"transformRequest": {},
"transformResponse": {},
"timeout": 180000,
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
"maxContentLength": -1,
"headers": {
"Accept": "application/json, text/plain, /*",
"Content-Type": "application/json",
"authorization": "Bearer JA.ZWU",
"Accept-Language": "en_US"
},
"method": "post",
"url": "https://api.uber.com/v1.2/requests",
"data": "{\"start_latitude\":40.8037381,\"start_longitude\":-73.9577813,\"end_latitude\":40.68780810000001,\"end_longitude\":-73.8057292,\"fare_id\":\"7636a3afa24d7648656aabbcc695bf094d4eed6d9323f3b10a5a5868a47c\",\"product_id\":\"b64-5de2-4539-a35a-986d6e58f186\",\"payment_method_id\":\"0xxxx-90ce-4c1d-a8c4-af7b1a00c3cf\"}"
},
"request": {
"UNSENT": 0,
"OPENED": 1,
"HEADERS_RECEIVED": 2,
"LOADING": 3,
"DONE": 4,
"readyState": 4,
"status": 400,
"timeout": 180000,
"withCredentials": true,
"upload": {},
"_aborted": false,
"_hasError": false,
"_method": "POST",
"_response": "{\"meta\":{},\"errors\":[{\"status\":400,\"code\":\"invalid_payment\",\"title\":\"The rider's payment method is invalid and they must update their billing info.\"}]}",
"_url": "https://api.uber.com/v1.2/requests",
"_timedOut": false,
"_trackingName": "unknown",
"_incrementalEvents": false,
"responseHeaders": {
"Server": "nginx",
"Strict-Transport-Security": "max-age=604800",
"X-Frame-Options": "SAMEORIGIN",
"Content-Type": "application/json",
"Content-Geo-System": "wgs-84",
"Date": "Fri, 05 Apr 2019 06:28:50 GMT",
"X-Content-Type-Options": "nosniff",
"Content-Length": "151",
"Cache-Control": "max-age=0",
"Connection": "keep-alive",
"X-XSS-Protection": "1; mode=block"
},
"_requestId": null,
"_headers": {
"accept": "application/json, text/plain, /*",
"content-type": "application/json",
"authorization": "Bearer JA.VUNU",
"accept-language": "en_US"
},
"_responseType": "",
"_sent": true,
"_lowerCaseResponseHeaders": {
"server": "nginx",
"strict-transport-security": "max-age=604800",
"x-frame-options": "SAMEORIGIN",
"content-type": "application/json",
"content-geo-system": "wgs-84",
"date": "Fri, 05 Apr 2019 06:28:50 GMT",
"x-content-type-options": "nosniff",
"content-length": "151",
"cache-control": "max-age=0",
"connection": "keep-alive",
"x-xss-protection": "1; mode=block"
},
"_subscriptions": [],
"responseURL": "https://api.uber.com/v1.2/requests"
}
}
Actual result should be ride request accepted.

POSTGRESQL: ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification

I am trying to perform upsert operation against a table named "message_payload", using below query, but get the error:
ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification
SQL state: 42P10
Query:
INSERT INTO public.error_message(
id, created_by, created_dt, modified_by, modified_dt, attempt, message_headers,
message_main_topic, message_payload, message_status, message_status_code)
VALUES (51, null, null, null, null, 1, '{
"jsonContent": {
"content-length": "1635",
"message_status_code": "417",
"cookie": "JSESSIONID=279AF4C174E6192BDAB11A067768BBD5",
"postman-token": "f0f33e86-498f-452a-aaf6-18eb84dc5907",
"kafka_timestampType": "CREATE_TIME",
"message_id": "21",
"kafka_receivedMessageKey": "null",
"kafka_receivedTopic": "error-topic",
"accept": "*/*",
"kafka_offset": "33",
"kafka_consumer": "org.apache.kafka.clients.consumer.KafkaConsumer#5091bb5f",
"host": "localhost:8082",
"content-type": "application/json",
"connection": "keep-alive",
"cache-control": "no-cache",
"kafka_receivedPartitionId": "0",
"kafka_receivedTimestamp": "1552305428711",
"accept-encoding": "gzip, deflate",
"message_main_topic": "ldarsQCustomStatistics.1",
"user-agent": "PostmanRuntime/7.6.1"
}
}', 'ldarsQCustomStatistics.1', '{
"jsonContent": {
"messageTime": 16772223422,
"messageRev": 9,
"businessId": "DB",
"messageId": "55"
}
}', 1, 201)
ON CONFLICT ((message_payload->'jsonContent'->>'message_id'))
DO UPDATE SET attempt = error_message.attempt + 1, message_headers = EXCLUDED.message_headers,
message_status_code = EXCLUDED.message_status_code, message_status = EXCLUDED.message_status,
created_by = EXCLUDED.created_by, created_dt = EXCLUDED.created_dt,
modified_by = EXCLUDED.modified_by, modified_dt = EXCLUDED.modified_dt,
message_main_topic = EXCLUDED.message_main_topic, message_payload = EXCLUDED.message_payload,
id = DEFAULT
You are most likely missing a unique constraint on this particular field.
Example:
CREATE UNIQUE INDEX j_msgid_idx ON public.error_message((data->'jsonContent'->>'message_id'));

POSTGRESQL: ERROR: column reference "attempt" is ambiguous

I get
ERROR: column reference "attempt" is ambiguous LINE 101: DO UPDATE SET attempt = attempt + 1;
I am trying to auto increment the column attempt. Alias is not supported with insert, but I am not sure what is wrong here.
INSERT INTO public.error_message(
id, created_by, created_dt, modified_by, modified_dt, attempt, message_headers, message_main_topic, message_payload, message_status, message_status_code)
VALUES (51, null, null, null, null, 1, '{
"jsonContent": {
"content-length": "1635",
"message_status_code": "417",
"cookie": "JSESSIONID=279AF4C174E6192BDAB11A067768BBD5",
"postman-token": "f0f33e86-498f-452a-aaf6-18eb84dc5907",
"kafka_timestampType": "CREATE_TIME",
"message_id": "21",
"kafka_receivedMessageKey": "null",
"kafka_receivedTopic": "error-topic",
"accept": "*/*",
"kafka_offset": "33",
"kafka_consumer": "org.apache.kafka.clients.consumer.KafkaConsumer#5091bb5f",
"host": "localhost:8082",
"content-type": "application/json",
"connection": "keep-alive",
"cache-control": "no-cache",
"kafka_receivedPartitionId": "0",
"kafka_receivedTimestamp": "1552305428711",
"accept-encoding": "gzip, deflate",
"message_main_topic": "ldarsQCustomStatistics.1",
"user-agent": "PostmanRuntime/7.6.1"
}
}', ‘abcd.1’, '{
"jsonContent": {
"messageTime": 16772223422,
"messageRev": 9,
"businessId": "DB",
"messageId": "55",
"deviceId": "DB_1234_SMM",
"assetType": "Locomotive",
"messageType": "thirdparty-timeseries",
"assetId": "DB_1234",
"appId": "ThirdPartyApp",
}
}', 1, 201)
ON CONFLICT ((message_payload->'jsonContent'->>'message_id'))
DO UPDATE SET attempt=attempt+1
To avoid an ambiguity between the original table row and the excluded inserted row, qualify the UPDATE:
DO UPDATE SET attempt = error_message.attempt + 1

Unauthorized payment error in paypal while using LIVE credentials

I am using Paypal REST API for payments.All was working fine with sandbox credentials but when I switched to LIVE credentials.It is giving errors like this :
Request to paypal API :
{
"body": {
"intent": "sale",
"payer": {
"payment_method": "credit_card",
"funding_instruments": [
{
"credit_card_token": {
"credit_card_id": "CARD-7314506536077511MK7WL121",
"payer_id": "57ecbbed656c78519a28382c"
}
}
]
},
"transactions": [
{
"amount": {
"currency": "USD",
"total": 10
},
"description": "Payment taken from customer Neha for booking #SR1032 and to be send to SP Neha and SP paypal Id hello#y.bom"
}
]
},
"header": {
"x-pp-ads-performed": "false",
"content-length": "374",
"pp_remote_addr": "54.244.2.156",
"paypal-request-id": "2afb7a93-0cc2-4ab2-b216-45b8de908f9f",
"pp_geo_loc": "US",
"x-pp-silover": "name=LIVE3.API.1&silo_version=880&app=platformapiserv&TIME=2734681175&HTTP_X_PP_AZ_LOCATOR=",
"host": "api.paypal.com",
"accept": "application/json",
"client-auth": "No cert",
"connection": "close",
"x-pp-idempotencyid": "eabb84d3ef438_1475149730",
"x-slr-orig-script_uri": "https://api.paypal.com/v1/payments/payment/",
"x-pp-slingshot-targetapp": "platformapiserv",
"x-pp-corrid": "eabb84d3ef438",
"user-agent": "PayPalSDK/PayPal-node-SDK 1.6.9 (node v4.5.0-x64-linux; OpenSSL 1.0.2h)",
"content-type": "application/json",
"authorization": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx9T1G"
},
"additional_properties":
Response from paypal server
{
"status": 401,
"duration_time": 49,
"body": {
"message": "Unauthorized payment.",
"debug_id": "eabb84d3ef438",
"information_link": "https://developer.paypal.com/webapps/developer/docs/api/#UNAUTHORIZED_PAYMENT",
"name": "UNAUTHORIZED_PAYMENT"
},
"additional_properties": {},
"header": {
"Content-Length": "191",
"Content-Language": "*",
"CORRELATION-ID": "eabb84d3ef438",
"Date": "Thu, 29 Sep 2016 11:48:50 GMT",
"Connection": "close",
"Paypal-Debug-Id": "eabb84d3ef438",
"PROXY_SERVER_INFO": "host=dcg12javapapi7866.dcg12.slc.paypalinc.com;threadId=704",
"Content-Type": "application/json"
}
}