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%'
Related
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.
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
This question already has answers here:
Get id from INSERT or SELECT
(3 answers)
Return rows from INSERT with ON CONFLICT without needing to update
(1 answer)
Is SELECT or INSERT in a function prone to race conditions?
(3 answers)
Closed 4 years ago.
What is the easiest way to insert a row in a database and returning its id if that row doesn't exist, otherwise return the ID of that word?
INSERT INTO mytable (name)
SELECT 'd'
WHERE NOT EXISTS (SELECT id FROM mytable WHERE name='d')
RETURNING id
This code works only if the row doesn't exist.
I either do that and then a SELECT, or try the INSERT with ON CONFLICT DO NOTHING and then a SELECT again.
Is there a better solution?
This question already has an answer here:
Populate Postgres database with numbers 1-1000?
(1 answer)
Closed 5 years ago.
I have a single table with a single column called id as shown below. I need to populate the table with numbers 1-1000, how can I do that with the scripting?
Use generate_series to this:
--Without column declaration
INSERT INTO "MyTable" SELECT generate_series(1, 1000);
--With column declaration
INSERT INTO "MyTable"(id) SELECT generate_series(1, 1000);
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=>