-- Let's say we update some data in a table. UPDATE my_table SET column1 = 'new_value' WHERE id = 42;-- Now, we want to know how many rows got changed and if there's a unique ID for the last row.
GET DIAGNOSTICS rows_affected = ROW_COUNT, last_oid = RESULT_OID;-- We can print these values to see what happened.
RAISE NOTICE 'Rows affected: %, Last OID: %', rows_affected, last_oid;
CREATE OR REPLACE FUNCTION example_function() RETURNS void AS $$ BEGIN -- Some code here -- Raise a notice message RAISE NOTICE 'This is a notice message: %', 'Additional data'; -- More code here END; $$ LANGUAGE plpgsql;
# Strings empty_string = "" non_empty_string = "Hello, world!"empty_string.empty? # => true
non_empty_string.empty? # => false# Arrays
empty_array = []
non_empty_array = [1, 2, 3]empty_array.empty? # => true
non_empty_array.empty? # => false# Hashes
empty_hash = {}
non_empty_hash = { name: "John", age: 30 }empty_hash.empty? # => true
non_empty_hash.empty? # => false
AVG(column_name)
ROUND(numeric_expression, number_of_decimal_places)
const person = { firstName: "John", lastName: "Doe", age: 30, address: { street: "123 Main St", city: "Anytown", state: "CA", zip: "12345", }, };console.dir(person);/* output: Object age: 30 address: Object city: "Anytown" state: "CA" street: "123 Main St" zip: "12345" firstName: "John" lastName: "Doe" */
expresion operator ANY(subquery)
SELECT 3 = ANY (ARRAY[1, 2, 3, 4]); -- Returns TRUE SELECT 42 = ANY (SELECT column FROM some_table); -- Returns TRUE if 42 exists in the column SELECT 'apple' = ANY (VALUES ('banana'), ('apple'), ('cherry')); -- Returns TRUE
SELECT COALESCE(null, 42, 'Hello'); -- Returns 42
REPLACE(original_string, search_string, replacement_string)
or
SELECT REPLACE('Hello, World!', 'World', 'Universe'); -- Returns 'Hello, Universe!'
SELECT CEIL(5.2); -- Returns 6
SELECT CEIL(-3.8); -- Returns -3
SELECT CEIL(10); -- Returns 10 (no change as it's already an integer)
SELECT FLOOR(5.7); -- Returns 5 SELECT FLOOR(-3.2); -- Returns -4 SELECT FLOOR(10); -- Returns 10 (no change as it's already an integer)
SELECT employee_name, salary, CASE WHEN salary < 30000 THEN 'Low Income' WHEN salary >= 30000 AND salary < 60000 THEN 'Medium Income' WHEN salary >= 60000 THEN 'High Income' ELSE 'Unknown' END AS income_category FROM employees;
async function* fetchUsers() { let page = 1; const perPage = 10; // Number of users per page
while (true) { const response = await fetch(`https://api.example.com/users?page=${page}&per_page=${perPage}`); const users = await response.json();
if (users.length === 0) { // No more users to fetch break; }
for (const user of users) { yield user; }
page++; } }
// Usage:
const userGenerator = fetchUsers();(async () => {
for await (const user of userGenerator) {
console.log(`User: ${user.name}, Email: ${user.email}`);
}
})();
{ "range": { "price": { "gte": 20, "lte": 50 } } }
{ "range": { "event_date": { "gte": "2023-01-01", "lte": "2023-12-31" } } }
SELECT regexp_match(column_name, 'your_regex_pattern') AS matched_text FROM table_name;