how to solve ** relation "dual" does not exist ** problem in PostgreSQL [duplicate] - postgresql

This question already has answers here:
Equivalence of from dual in PostgreSQL
(5 answers)
Closed 7 months ago.
I'm trying to convert Oracle to PostgreSQL. While converting I'm getting error like
relation "dual" does not exist .
EXECUTE 'SELECT DBMS_RANDOM.VALUE*(POWER(10,6)) FROM DUAL'
please help me to solve this error.

Dual is a dummy table specific for oracle. In PostgreSQL you can either just use
SELECT random()*power( 10, 6 );
or create your own dual table if you want to keep the dual. (and insert 1 row in it)

You can create a view named dual like:
CREATE VIEW public.dual AS SELECT 'X'::varchar AS dummy;
REF: https://pgpedia.info/d/dual-dummy-table.html

Related

One query runs fine but a very similar one does not run at all [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)
Closed 1 year ago.
I have been using SQL for many years, but I am pretty new to postgresql. I'm using pgAdmin and I'm running the following query just fine.
select *
from budget_spending
where market is not null
limit 10
However, this query does NOT run.
select *
from budget_spending
where Project_Description is not null
limit 10
I get this error message:
ERROR: column "project_description" does not exist
This is very bizarre, because I'm looking at it and it certainly does exist. If I right-click the column and go to Properties, I see 'Project_Description' as the name of the column. What am I missing here?

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.

Postgres 11 INSERT ON CONFLICT SELECT * [duplicate]

This question already has an answer here:
Postgres 9.5 ON CONFLICT DO SELECT
(1 answer)
Closed 3 years ago.
I am trying to insert a row into a table, if that insert succeeds I would to return the newly inserted row. If that insert fails, I would to select a row using some of the values I already know to be on that row.
For example, table 'reports' has 3 columns, so far I have the following:
INSERT INTO reports (col2, col3) VALUES ($1, $2)
ON CONFLICT ON CONSTRAINT custom_index DO
SELECT * FROM reports WHERE col1=$1 AND col2=$2;
For those who will ask, custom_index was created using:
CREATE UNIQUE INDEX custom_index ON reports (col2) INCLUDE (col3);
The current error I am getting is
syntax error at or near "SELECT"
Select is not allowed in the conflict.
Check the documentation https://www.postgresql.org/docs/current/sql-insert.html.
Related question is already answered.. Postgres 9.5 ON CONFLICT DO SELECT

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%'

Insert script to auto populate numbers 1-1000? [duplicate]

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);