In my Golang application I make SQL request to the database. Usually, in the SQL query, I specify the columns that I want to get from the table and create a structure based on it. You can see an example of the working code below. QUESTION: What should I do if I don’t know the number and name of columns
Tag: json
PostgreSQL: exclude complete jsonb array if one element fails the WHERE clause
Assume a table json_table with columns id (int), data (jsonb). A sample jsonb value would be When I use an SQL statement like the following: … the two array elements are unnested and the one that qualifies the WHERE clause is still returned. This makes sense since each array element is considered individually. In this example I will get back
How do I parameterize this jsonb array contains query?
I have the following sql: Which gives me (as expected): 789019 | 789019 Now, I need to parameterize the query but am unable to: I get an empty row and that’s because it is literally searching for “$1”. I try to remove the double quotes then it complains I’m not sure how to resolve this one. Answer If you just
Select query to group records in output json using BigQuery
I have a datetime partitioned table in BigQuery with a schema like: So, if I do a SELECT * FROMmy_table`, it will generate a JSON with a structure like: And that format works well in most of my use cases, except for one. So, if I wanted the id’s of all the inverters i would do But I also need
How to search JSON array field in MySQL?
I have a column which has json type arrays like How can i use where clause to find “abc” contained rows? My json arrays has no key. They only have values. returns 0 rows Answer You can use MySQL JSON search function JSON_CONTAINS():
PostgreSQL json_build_object nested
First things first: I’m using PostgreSQL 11.6, compiled by Visual C++ build 1800, 64-bit. 🙂 Im trying to create a JSON object directly from the database. My desired result is { “1”: [], “…
Querying JSONB array value for sub values?
I have a JSONB Object: It is stored in a jsonb column of a table So i was trying to get a count by name of devices which have interfaces that are not ‘up’. Group By is used for developing counts by naame, but i am having issues querying the json list for values. MY first Attempt was: Some surrounding
How to query Json array in jsonb in Postgresql
I have a jsonb column which have following rows ROW1: [ { “cpe23Uri”: “cpe:2.3:a:sgi:irix:3.55:*:*:*:*:*:*:*”, “active”: true }, { “…
How can I generate JSON results in older SQL Server versions?
I have a table which contains data similar to this. I want to get ItemNames in JSON format as I have mentioned in the expected output below. Expected output: Note: I know in latest SQL Server, there are functions FOR JSON to convert to JSON format but it won’t work in older SQL versions. Therefore, I am expecting the answer
How to parse a json object – mysql
I have a json object like this: {“1”: {“penalty_percent”: 3, “free_day”: 5, “free_hours”: 24}, “2”: {“penalty_percent”: 2, “free_day”: 5, “free_hours”: 12}, “3”: {“penalty_percent”: 2, “free_day”: 2, …