833 questions
1
vote
2
answers
65
views
How to pass a list of locations (longitude, latitude) to a PostgreSQL/PostGIS stored function?
I have prepared a DB fiddle for my questions and also list my SQL code below.
I have created a countries_boundaries table, which I intend to fill with .poly files provided at Geofabrik:
CREATE ...
-1
votes
1
answer
45
views
Convert a Stored Procedure to a Stored Function in MYSQL
Is it possible to change this stored procedure to a stored function? I created the procedure thinking it was a requirement for my coursework, when in fact I need a stored function.
I'd rather not ...
0
votes
0
answers
35
views
Stored function for finding exact string match is always returning false
I am trying to create a stored function that checks to see if an exact string has been used already. This function that I have created always returns FALSE though, even when I set the RETURNS datatype ...
0
votes
1
answer
71
views
How to generate unique grouped autoincrement document id's? [duplicate]
I need to make some tables which are able to auto-increment unique document names for each month of the year based on the date of each documnet type. I think it will be a good idea to make it as a ...
0
votes
1
answer
52
views
Postgresql: Error executing select into statement within a function
Consider the following statement:
create function get_most_frequent_topic(out topic_id integer)
as $$
begin
select
p.topic_id into topic_id,
count(*) as freq
from post p
...
0
votes
1
answer
116
views
Unable to execute mysql script - 'CREATE FUNCTION' or 'CREATE TRIGGER' via Python
I do have troubles with my sql scripts which I've wrote priorely and try to read with my python code and also execute it. Here my simple mysql script, where the DELIMITER command is removed:
DROP ...
1
vote
1
answer
863
views
PostgreSQL: ERROR: query returned 2 columns
My function is like this:
CREATE OR REPLACE FUNCTION insert_o_record_desc()
RETURNS text
LANGUAGE 'plpgsql'
AS $$
DECLARE
o_record TEXT DEFAULT '';
rec_o_record RECORD;
cur_o_record CURSOR ...
0
votes
2
answers
436
views
MySQL/MariaDB Create multiple inserts from function
In an SQL function I want to create multiple records based on the parameters passed into the function, for example the function takes a member primary ID, a date/time stamp and a number specifying the ...
-3
votes
2
answers
62
views
How can I fix my Function to show different results?
Can someone review my code and guide me what did I do wrong? I managed to create stored function. However, after selecting, the only result for hotellevel is silver.
CREATE FUNCTION HotelLevel
(
@...
0
votes
1
answer
120
views
Atomicity of stored functions
Unlike stored procedures, which can explicitly start & commit transactions, stored functions can't contain "Statements that perform explicit or implicit commits or rollbacks". ...
0
votes
1
answer
822
views
How to return 2 items from 2 different tables within 1 query in Spring JPA?
I have a postgres query within my springboot app that needs to return a list with each element (being an array) containing 2 items from 2 different tables. The entities for each table are as follows:
...
1
vote
2
answers
699
views
Bigquery aggregate column array data
Considering a BigQuery view that has one column ARRAY<STRUCT<col1 FLOAT, col2 FLOAT>> called X.
Which is the best way to retrieve those rows with an additional column that is a computation ...
0
votes
1
answer
798
views
Invoking REST API through SQL Stored Proc
We are working with Azure Data Factory and there is this pipeline in which I am trying to check the response of an API which reports a pipeline status. If it returns 'InProgress', I want to wait for ...
0
votes
1
answer
157
views
How to write a PostgreSQL stored function to alter jsonb array?
I am trying to write a simple stored function in PostgreSQL .
This function will receive two parameters . (details jsonb & provider_details jsonb[] ) .
details jsonb example :- {"category&...
0
votes
0
answers
26
views
Remaking request to the function
I need to turn this request to the function
SELECT object_id, brigade_code, date_and_time
FROM purpose
WHERE date_and_time BETWEEN '2022-06-15 16:20:23' AND '2022-10-03 18:12:45';
My best attempt
...
0
votes
1
answer
208
views
How to convert this into postgresql stored procedures in nodejs
I want to change the postgresql queries to stored procedures in Nodejs.
app.post("/add", async(req, res) => {
try {
const { name, email, hobby } = req.body;
const newStudent = ...
0
votes
1
answer
508
views
Using CASE Statement in Stored Function MySQL
I am creating a stored function in MYSQL Workbench that takes a date and returns the quarter of that fiscal year. I came up with the following code script. The SQL Editor checked the statements and ...
0
votes
1
answer
13
views
stored function using time datatype not working
`DELIMITER //
CREATE FUNCTION am_or_pm (crying_time TIME)
RETURNS varchar(20)
DETERMINISTIC
BEGIN
DECLARE am_or_pm varchar(20)
IF crying_time <= "11:59:00" THEN
set am_or_pm = 'AM';
...
0
votes
0
answers
72
views
DB2 function accepting rows
I have a function which is accepting an id from type varchar. The id represents the pk. But sometimes the pk consists more of two parameters. So is it possible to make the function more generic and ...
0
votes
1
answer
1k
views
Create stored procedure with optional parameters in postgres
I am trying to create either a function or a stored procedure in a Postgres database. I don't really know the syntax in Postgres. I am trying the following, but I know it is not complete.
Create or ...
0
votes
0
answers
53
views
Selecting Into Lag (Window Function) in MySQL Stored Function
I am trying to automate mathematic formulas that I need to run many times over a dataset for a view page. I have used the SELECT INTO function to successfully create these values. Below is an example ...
0
votes
2
answers
685
views
Postgres stored function return result of SELECT DISTINCT
I want to have an array of distinct integer values across my postgres table as the return value of a stored function.
The stored function currently looks like this
create or replace function ...
0
votes
0
answers
131
views
MongoDB: How to call stored function from nodejs
I'm trying to call stored function from node js using db.eval() and also provided the db connection and it is giving an error - Type Error: db.eval() is not a function.
I'm facing difficulty while ...
1
vote
2
answers
66
views
How to return boolean based on number of records in database?
Here's what I've tried. My host is returning an error, "Sorry an unexpected error happened!" .
I want it to return true if there is at least 1 record with combination pdriver_id, ...
0
votes
1
answer
54
views
Conditional Stored Procedure to edit specific records
Hi and thanks in advance for your help
I am struggling to write a stored procedure in sql server to manipulate some records which are batch imported from a csv file without any particular order.
Each ...