Questions tagged [sql-procedure]

12 questions
7
votes
1 answer

How to use variables in procedure (not function)?

As I understand, in Postgres, procedures are for manipulating data and functions are for reading data. I would like to: declare a variable select a value into a variable insert the variable into another table do this in a transaction do this in a…
3
votes
1 answer

"column ... does not exist" error when calling an SQL procedure (new in PostgreSQL 11)

Using PostgreSQL 11 Beta 2, a very simple trading_holiday table is created in the config schema: DROP TABLE IF EXISTS config.trading_holiday; CREATE TABLE config.trading_holiday ( id smallint GENERATED ALWAYS AS IDENTITY NOT NULL, holiday_date…
1
vote
1 answer

How to return values from psql to bash with custom session settings

I need to set the datestyle to "dd/mm/yyyy" before calling a procedure and getting it's return value back to bash. I tried the following: read return <<< $(psql \ -x \ -U postgres \ -d MY_DB \ …
Majd
  • 121
  • 3
1
vote
2 answers

Inject aggregation function inside a procedure

Is it possible to inject the name of a function (AVG, MAX...) as a procedure parameter? CREATE PROCEDURE test(func TEXT) LANGUAGE PLPGSQL AS $$ BEGIN DROP TABLE IF EXISTS foo; CREATE TEMPORARY TABLE foo AS SELECT func(bar.column_a) as…
1
vote
1 answer

MYSQL Stored procedure to fetch entire row from a table

I am a beginner to SQL and currently practicing the concept of the stored procedure. I have a table Fetch_Marks that contains 20 records with Student_No and Marks as columns. Now I would like to create a stored procedure for this in which the input…
0
votes
0 answers

create procedure function as alternative to DB timeout

So I am fairly new to sql and there is a particular query I make where the DB always timeout. I tried everything, including restarting the server. There is this table where it listed all the events happening in an app, together with the person_role…
orrie881
  • 1
  • 2
0
votes
1 answer

How to write SQL Stored Procedure to ouput a fixed Length/width File

I am using SQL server 2017, I want to write SQL stored procedure to generate a fixed length/width file without using SSIS or wizard TABLE: EmpID EmployeeName Department Birthdate Hiredate 001 John…
Y.agr
  • 13
  • 2
0
votes
1 answer

How to issue a DML with WHERE clause comparing a value which is trigger generated in table?

Suppose I have a table with CREATE, CREATE TABLE TEST ( year int, month int, date int, hr int, min int, sec int, timestamp timestamp, value double ); CREATE FUNCTION timestamp_insert() RETURNS trigger LANGUAGE…
Vineet Menon
  • 185
  • 1
  • 6
0
votes
1 answer

Pull multiple fields from table B where a specific value from Table A is not in Table B

SQL Newbie here. I have a question about pulling multiple fields from a database when one value is not in another table. I have two tables: "Contact" table - contains all of our contact information such as their email address, contact creation…
-2
votes
1 answer

How to auto run oracle stored procedure

Is there any possibility to auto run procedure after a specific time/date? For example I want to auto run this stored procedure after 2 days: CREATE OR REPLACE PROCEDURE deleteresetlinks AS BEGIN DELETE FROM passwordresetlink WHERE date_created…
-2
votes
1 answer

MySQL trigger calling stored procedure always get null value for out parameter of stored procedure

My stored procedure OUT parameter, always return a null value. Here is sample Table, Trigger and Procedure code. Table: test Columns: id - Int status - enum(‘pass’, ‘fail’) status - enum(‘pass’, ‘fail’) (null is allowed) Values in a table: id …
Krunal
  • 101
  • 5
-2
votes
1 answer

Procedure to change a person's designation

People are occasionally moved between different departments. I want to create a procedure that accepts a name (name of person) and a department(department that person is assigned to) and changes the person's department assignment to a new…
Redsam121
  • 3
  • 2