This draft deletes the entire topic.
Examples
-
-
SELECT CURRENT_DATE + '1 day'::INTERVAL
SELECT '1999-12-11'::TIMESTAMP + '19 days'::INTERVAL
SELECT '1 month'::INTERVAL + '1 month 3 days'::INTERVAL
-
-
DELETE FROM <SCHEMA_NAME>.<Table_NAME> WHERE ctid NOT IN ( SELECT MAX(ctid) FROM <SCHEMA_NAME>.<TABLE_NAME> GROUP BY <SCHEMA_NAME>.<TABLE_NAME>.* ) ;
-
Monthwise difference between two dates(timestamp)
select ( (DATE_PART('year', AgeonDate) - DATE_PART('year', tmpdate)) * 12 + (DATE_PART('month', AgeonDate) - DATE_PART('month', tmpdate)) ) from dbo."Table1"
Yearwise difference between two dates(timestamp)
select (DATE_PART('year', AgeonDate) - DATE_PART('year', tmpdate)) from dbo."Table1"
-
0Query to Copy/Move/Transafer table data from one database to other database table with same schema
First Execute
CREATE EXTENSION DBLINK;
Then
INSERT INTO <SCHEMA_NAME>.<TABLE_NAME_1> SELECT * FROM DBLINK( 'HOST=<IP-ADDRESS> USER=<USERNAME> PASSWORD=<PASSWORD> DBNAME=<DATABASE>', 'SELECT * FROM <SCHEMA_NAME>.<TABLE_NAME_2>') AS <TABLE_NAME> ( <COLUMN_1> <DATATYPE_1>, <COLUMN_1> <DATATYPE_2>, <COLUMN_1> <DATATYPE_3> );
-
update <SCHEMA_NAME>.<TABLE_NAME_1> AS A SET <COLUMN_1> = True FROM <SCHEMA_NAME>.<TABLE_NAME_2> AS B WHERE A.<COLUMN_2> = B.<COLUMN_2> AND A.<COLUMN_3> = B.<COLUMN_3>
Please consider making a request to improve this example.
Still have a question about Postgres Tip and Tricks?
Ask Question
Topic Outline
- Comma seperated values of a column
- DATEADD alternative in Postgres
- Delete duplicate rcords from postgres table
- Difference between two date timestamps month wise and year wise
- Query to Copy/Move/Transafer table data from one database to other database table with same schema
- Update query with join between two tables alternative since Postresql does not support join in update query.
Sign up or log in
Save edit as a guest
Join Stack Overflow
Using Google
Using Facebook
Using Email and Password
We recognize you from another Stack Exchange Network site!
Join and Save Draftlang-sql