« first day (3374 days earlier)      last day (1791 days later) » 

06:17
Morning
Amusing juxtaposition of starred comments this morning:
Ell
Ell
06:36
Afternoon everybody
sorry, morning :P
I couldn't see any rules so I'm going to assume it's okay for me to ask for help in here?
Generally you should ask a question.
Post a question on the main site, that is.
But if you don't know where to begin, start here and we'll definitely try to help you!
Ell
Ell
ah it's okay, if I should ask a question I'll ask a question :)
Now I'm curious :-)
Ell
Ell
haha
I'm trying to use INSERT as a subquery but I'm not sure if that's possible. it's a little difficult to google because of all of the questions asking about subqueries inside INSERT
in a nutshell, I have some rows e.g. ```(1, 3), (4, 2), (null, null), (3, 7), (null, 3)```
and I want to ```INSERT``` the sum of the two values somewhere and have the query return results like this:
```(4), (6), (null), (10), (null)```
oh dear I missed the edit time, sorry. Better ask a question
I think I understand what you're trying to do.
06:45
I don't understand, but that's come to be expected
Not sure if it's possible actually, but can see why you might want to do that in a single query to save processing time
Ell
Ell
I have a feeling it's not possible too :/
I'm not sure how exactly to title this question. Something like: "Include non-inserted rows as result of INSERT INTO ... RETURNING" ?
any better ideas?
or potentially "INSERT INTO inside CASE" (though this is a little more XY)
The first title is better
Ell
Ell
okay I'll use that
@Colin'tHart I'm doing it because I have a bunch of data that I'm importing column-wise where there are some queries (like this) which depend on the results of previous "row-wise" queries
if, for a particular row, a query fails, a query inspect a later column needs to know
Does anyone know whether it is possible to call function that returns a table inside the FROM clause of an SQL query in postgresql?
07:10
@PrashinJeevaganth yeah that works
How does the query structure look like?

select T2.A1, T2.A2
from Table1 T1, f(T1.a) T2
?
like it would with an actual table yes. Old type joins should be avoided though (not only with functions)
07:29
@Ell Always just the previous row in that case?
Or do you need to look further back?
LAG() can be used to look back at the previous row -- why not solve it in the same query?
 
2 hours later…
09:16
Morning
09:42
morning
morning
 
2 hours later…
11:17
@Ell you haven't told what DBMS you use. Postgres, SQL Server, Oracle, ...?
2
Q: Include non-inserted rows as result of INSERT INTO ... RETURNING

EllI'm using PostgreSQL 11. I want to conditionally insert values into a table while having the result of the insertion include a null for each row of the input which did not result in an insertion. For example CREATE TABLE all_sums (sum INTEGER); SELECT CASE WHEN a_sum IS NULL THEN null ...

 
1 hour later…
12:40
thnx @TomV-trytopanswers.xyz
Listening suggestion for today:
Open in 2 tabs, let 1 flow for 1 minute, then start the 2nd
69
A: Feedback for The Loop: March 2020

Jon EricsonFrom the post: I heard feedback from a significant number of Stack Overflow employees that they avoided [posting] on Meta because of the reaction it garnered. Though this was not felt by all staff who interacted on Meta, and it affected different people to varying degrees, many felt discourag...

ouch
13:20
I like the answer above that. Along the line of: ...Taking responsibility for ones actions...
13:44
Well yes but I always link to the Shog answer.
Also that one struck me because Jon is usually so reserved
14:33
Does anyone mind telling me what's the syntax error to this function here? They told me it's around end. paste.ofcode.org/9iNJdnwRYVxdgBZCRANkdJ
14:48
Lipstick on a pig...
15:02
dork mode
3
 
2 hours later…
16:36
dark mood
17:01
Does anyone know how to select the only integer attribute value from a function into a variable declared in a trigger? For some reason I'm getting null instead of an integer. paste.ofcode.org/EyvhSkSHkTerL6VE8H4XWD
17:41
the only integer attribute value from a function?
a := SELECT 1;
functions have attributes?
@PrashinJeevaganth it could be an integer NULL
I think he just means how does he set a variable in plpgsql
CREATE FUNCTION f() RETURNS int AS $$ DECLARE foo int; BEGIN foo := 5; return foo; END; $$ LANGUAGE plpgsql;
18:01
@mustaccio I tested out the set of functions on a test case which produces integer output
But the integer is not recorded in the declared variable
I tried switching the function's return type to an int instead of a table too, still produces the same error
 
1 hour later…
19:13
@PrashinJeevaganth what error is that?
You could use dbfiddle.uk to setup a reproducible example. create the tables, the functions, the triggers and run them so we can see the error and make changes.
Just copy your code there and give us the link.
Second, is this trig_assign_rider() a trigger for updates on table Orders? If yes, why does it try to the whole table again?
If the aim is to change the value of the rider column in the same row that is updated, you need something much simpler
    elsif NEW.order_timestamp is not null then
        NEW.rider :=
            select T.rider
            from find_highest_priority_rider(NEW.order_timestamp) T;
        return NEW;
    end if;
or just, since the function returns an integer
    elsif NEW.order_timestamp is not null then
        NEW.rider := select find_highest_priority_rider(NEW.order_timestamp) ;
        return NEW;
    end if;
19:40
@ypercubeᵀᴹ Hmm this is the first time I've seen the := symbol
@ypercubeᵀᴹ Actually I dont get what you meant when you said I'm trying the whole table again
You have that where Orders.id = NEW.id; in the update which I thought it means you want to change the value of rider in the very same row you are updating.
No?
Hmm that makes sense
I didn't know how to update attribute values other than update statements
Both OLD and NEW are virtual rows, the same row you are updating. OLD has the values before the update, NEW has the values that will replace the old ones.
that is inside a trigger ^^
19:57
I see
Looks like I'm still having the null values
I don't play with triggers much but I think you also need to change it into a BEFORE trigger.
Hmm
Now that I look at it, I guess it might be possible
the first if statement prevents things from going wrong
you need a BEFORE trigger for my version above to work
> The return value is ignored for row-level triggers fired after an operation, and so they can return NULL.
Morning.
morning @MichaelGreen
20:04
Stop hogging this fine place with your one-on-one trigger tutorial drivel. Where are the food pics? Where's the coronavirus update? I ask you
Looks like I'm still getting null
54 mins ago, by ypercubeᵀᴹ
You could use dbfiddle.uk to setup a reproducible example. create the tables, the functions, the triggers and run them so we can see the error and make changes.
Just copy your code there and give us the link.
By any chance does the function not work the same way inside a function and outside
@PrashinJeevaganth No. But you can test that.
Mar 27 '19 at 13:45, by Peter Vandivier
repro is best-pro
20:14
@ypercubeᵀᴹ Ok thanks for your help once again
I will look into this link too
By the way, do any of you have recommendations for PostgreSQL textbooks? Like with query challenges preferably with answers?
Or maybe some books for database design is good too, I wanna learn more about when I could apply ternary relationships
Try to remove that first if and see if it works.
0
Q: Duplicate Not Linked

user369450I asked a question, a user flagged it as an appropriate duplicate of another question, and I accepted the question as a duplicate. My question now has the "This question already exists" banner, but the link to the older question is missing from the banner. Is this a bug? For reference this is ...

1
Q: Bug? A closed-as-dupe question does not have a link to the dupe

mustaccioHere's what I see when I open this question Notice there's no link to the dupe after "This question already exists". The comment with the link is also gone. This looks like a bug, as the question as it is now is entirely useless.

That's so meta, I'm seeing double
Or the other way around
I'll go close myself as a dupe
20:30
@ypercubeᵀᴹ The trigger without calling the helper function does work(modifying the value to a non-null value)
I guess the problem lies in that function
Did you try removing that if?
For laughs: suggestion for database book: amazon.com/Manga-Guide-Databases-Mana-Takahashi/dp/1593271905
2
@ypercubeᵀᴹ I wonder who's the target audience. With "SQL for Dummies" it's kinda obvious, but this?
@PrashinJeevaganth I remember a nice book about database design patterns that might suit for such questions but I can't remember the name. And it is about 3000 miles away ...
That's it. I'm starting a "for chipmunks" series. The first one will be about high availability and disaster recovery.
@ypercubeᵀᴹ I'm hesitant to ask, were you looking for a book to recommend to Prashin?
20:50
@mustaccio yeah but my good suggestion slips my mind at the moment. I only remember that the cover was grey ;)
so I offered a funny one ;)
 
2 hours later…
22:28
i have a special dislike right now for the empty string
2
@PeterVandivier Let me guess: it is null sometimes, and sometimes it is not.
@PeterVandivier have you started working with Oracle?
some proactive developer went ahead and made everything non-nullable in the model and then handled unknown values in app code by inserting the empty string
Your dislike is obviously misplaced. Dislike the "proactive developer" instead.
this is my hell
22:31
Try switching to the light mode
what is "Platanos"? sounds Greek
(if that's what it's called; I'd call it "normal")
today's listening suggestion:
it builds up slowly the first 4-5 min but then it just takes off

« first day (3374 days earlier)      last day (1791 days later) »