The function processes the sql request. It receives parameters and one of them can be either “null” or a value (uuid), I need to add this value to where. But there is a problem, because with null “where param is null”, but with the value “where param = value” Example Answer In sql, null = null and null <> null
Tag: postgresql
Postgres SQL Select two fields by most recent date, one field must be unique
I need to find which student belongs to which homeroom, as of the latest data inputted. Starting with this dataset: I want to only retrieve Alice’s most recent homeroom and Bob’s most recent homeroom: The typical answer of how to find the most recent record only applies to when you’re looking for one field’s recency: This is not what I
PostgreSQL, add row to table when a row is created in another table
I am trying to create a trigger function, to create a new row, in a table, when a value is modified or created in another table. But the problem is that I need to insert in the other table, the …
Convert Postgres IPv6 column TEXT field into JSON
Trying to convert a text field to a JSON field in Postgres. The field was an IPv6 address those having multiple semicolons e.g.: “14:eth1:vTA1:::4:” Trying to run smth like: Results in: Failed to convert text field to JSON. Details: invalid input syntax for type json DETAIL: Expected end of input, but found “:”. Any clues how to do it properly?
NoSQL or SQL for Data Structure [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 1 year ago. Improve this question I’m building an app, and this is my first time working with databases. I went with MongoDB because originally I
How to edit and return a Cursor in plpgsql?
I am doing a simple query inside a function, and I need to change the values of this query, but only for information. I don’t need to update the table as such. I managed to edit the values but I don’t know how to return them. And below this function will be executed As you can see, the query does
Create a Status column with 3 categories based on conditions in multiple columns in SQL
I have a table like this CREATE TABLE proc_code ( id INTEGER, c_date DATE, code VARCHAR(255) ); INSERT INTO proc_code (id, c_date, code) VALUES (101, ‘2017-12-21’, ‘3027f’), (101, ‘…
How to select from table A and then insert selected id inside table B with one query?
I’m trying to implement a very basic banking system. the goal is to have different types of transactions ( deposit, withdraw, transfer ) inside a table and refer to them as IDs inside transaction …
SQL to assign covid patients to hospitals
I have 2 tables: CREATE TABLE remdesivir_inventory ( hospital_id int, stock int, state varchar(2) ); CREATE TABLE remdesivir_requests ( patient_id int, prescribed_qty int, state varchar(2) ); I want …
Increment a column value of an entity in an SQL table
I’ve set up the following table: CREATE TABLE transactions (txn_id SERIAL, stock VARCHAR NOT NULL, qty INT NOT NULL, user_id INT NOT NULL); On inserting few rows, the table looks like this: txn_id | …