I am having a syntax error in the MERGE statement [duplicate] - postgresql

This question already has answers here:
Need to convert Oracle "merge into" query to PostgreSQL
(1 answer)
Migrating an Oracle MERGE statement to a PostgreSQL UPSERT statement
(3 answers)
Merge statement with two conditions in same CLAUSE alternative in Postgres
(1 answer)
PostgreSQL Upsert with a WHERE clause
(1 answer)
Closed 2 years ago.
I have postgres 12.3 and find an error in a simple MERGE statement like below:
MERGE INTO lkup_language a
USING (SELECT *
FROM dblc_stg.stg_lkup_home_language
WHERE home_lang_code NOT IN (SELECT home_lang_code
FROM dblc_stg.stg_lkup_home_language
GROUP BY home_lang_code
HAVING COUNT (*) > 1)) b
ON (a.language_cd = b.home_lang_code)
WHEN NOT MATCHED THEN
INSERT (a.language_key, a.language_cd, a.language_desc)
VALUES (NEXTVAL('SEQ_LKUP_LANGUAGE'),b.home_lang_code, b.home_lang_desc)
WHEN MATCHED THEN
UPDATE
SET a.language_desc = b.home_lang_desc ;
I hope I get some help
Thanks
Ajay

Related

Getting an error on a Postgres table "ERROR: column does not exist" that doesn't make sense to me [duplicate]

This question already has answers here:
PostgreSQL "Column does not exist" but it actually does
(6 answers)
sql statement error: "column .. does not exist"
(1 answer)
PostgreSQL column 'foo' does not exist
(12 answers)
SQL query column does not exist error
(1 answer)
Closed 1 year ago.
In pgAdmin if I do a simple select:
"select * from NFT where item_id = 1271" I get what I would expect:
However, when I try to query on this other column: "select * from NFT where tokenID = 40" I get an error: "ERROR: column "tokenid" does not exist
I'm new to Postgres in the last year, have used it quite a bit but this one has me stuck on how to proceed. It's just a normal column.
any ideas?

What is the exact way of using where clause in PostgreSQL 12? [duplicate]

This question already has answers here:
PostgreSQL "Column does not exist" but it actually does
(6 answers)
sql statement error: "column .. does not exist"
(1 answer)
Postgres column does not exist
(1 answer)
Closed 1 year ago.
I am trying to query a table using where clause in Postgres 12
case 1
SELECT *
FROM schema.e_employee_table
WHERE FK_EMPLOYEE=100;
so when i query the above query i get "FK_EMPLOYEE" column is missing.
case2:
SELECT *
FROM schema.e_employee_table
WHERE "FK_EMPLOYEE"=100;
when i query the above one i got the query results
So can someone explain do we need to put our column name inside "",is it the syntax. If so where it is mentioned in the official documentation.
And I can also see the column name we are mentioning is case sensitive.

How to turn off postgresql case sensitive search? [duplicate]

This question already has answers here:
How to make "case-insensitive" query in Postgresql?
(14 answers)
PostgreSQL accent + case insensitive search
(2 answers)
Case Insensitive searches/queries
(2 answers)
How to make LIKE clause case-insensitive?
(2 answers)
PostgreSQL citext index vs lower expression index performance
(1 answer)
Closed 3 years ago.
I have a lot of sql query command that use "WHERE" clause, I have just wondered that my postgresql searching was case sensitive.
for example:
Select * From myarea Where area_name = 'Jawa Barat1' --> not found
Select * from myarea Where area_name = 'jawa barat1' --> found
How to turn off the case sensitive searching in postgresql?
Please don't suggest me to change the sql command to set to lowercase at both side.
expect postgresql to in-case-sensitive searching (Mother = mother)
demo:db<>fiddle
Using ILIKE comparator, which (as the LIKE comparator) works also with wildcards (see fiddle)
Select * From myarea Where area_name ILIKE 'Jawa Barat1'
Or normalize string with lower() which converts all letters to non-capitals. You have to use it for both comparing literals:
Select * From myarea Where lower(area_name) = lower('Jawa Barat1')

How to search for a variable name in PostgreSQL? [duplicate]

This question already has answers here:
How to find a table having a specific column in postgresql
(6 answers)
Closed 5 years ago.
I want to search for a particular variable name in ‘PostgreSQL’ database. Similar to the following ‘Teradata’ query
Select TableName, ColumnName from
DBC.Columns
Where ColumnName like (‘%profile%’)
Is there a similar query in PostgreSQL?
Postgres documentation
SELECT table_name,column_name
FROM information_schema.columns
WHERE column_name like '%profile%'

Execute a String Sql in PostgreSQL [duplicate]

This question already has answers here:
dynamic query postgres
(2 answers)
Closed 8 years ago.
In a function, I have a SELECT query in a string, for example:
sql='SELECT * FROM A'
I want to execute sql output result of: SELECT * FROM A
How can I execute the string sql in PostgreSQL?
Inside a function use EXECUTE.
http://www.postgresql.org/docs/current/interactive/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN
below one works fine in postgres 8.4
UDBI=> PREPARE query as select 1 as a;
PREPARE
UDBI=> PREPARE query
UDBI=> EXECUTE query;
a
---
1
(1 row)
UDBI=>