SELECT name,phone,email FROM res_partner;
Display all the records of res.partner's model, with name, phone and email attributes.
SELECT * FROM pg_catalog.pg_tables;
Display all the tables inside that database
SELECT datname FROM pg_database;
List of all the databases inside that postgreSQL
SELECT * FROM pg_user;
List of all the users using that postgreSQL
SELECT version();
The version of that postgreSQL
SELECT * FROM sale_order WHERE partner_id IN (SELECT id FROM res_partner WHERE name ILIKE '%Johnson%') LIMIT 5;
Show only the 5 first records of sale.order's model where their client have 'Johnson' in their name
WITH temporary_table AS (
SELECT pt.id AS pt_id, pp.id AS pp_id
FROM product_template pt
LEFT JOIN product_product pp
ON pp.product_tmpl_id = pt.id
)
SELECT * FROM temporary_table ORDER BY pt_id;
Associate each product template with their product variant
UPDATE res_users SET password = 'my_45_password' WHERE id = 10;
Modify the password to 'my_45_password' for the user with id = 10
UPDATE res_partner AS a SET email = CONCAT(a.name,'@company_mail.com');
Modify all the email of the contact within the rule 'name of the contact'+'@company_mail.com'
DELETE FROM sale_order WHERE write_date <= '2017-12-31'::date;
Delete old sale_orders that was last modified before the 2018 year
SELECT a.name,b.name FROM res_partner a INNER JOIN sale_order b ON a.id=b.partner_id;
Select the clients linked with their sales orders
CREATE TABLE mytable ( id Integer , name char(10) , description char(40) );
Create a table 'mytable' with a column for id,name and description
INSERT INTO mytable VALUES ( 30 , 'first rec' , 'this is a the first record' );
Insert row in the table 'mytable' with the corresponding column and type
ALTER DATABASE mycurrentdatabasename RENAME TO newnamefordatabase;
Give a new name to a database
DROP TABLE mytable;
Drop the table 'mytable'