Questions tagged [with-statement]

A number of languages have With statements. The Python with statement creates a new context, with associated context manager. When the context (a code block) is exited again, the context manager is notified. Please use "common-table-expression" for the SQL WITH construction.

A number of languages have With statements. Python's with statement creates a runtime context, defined by a . As the code block under the with statement is entered, a __enter__ hook is called on the context manager, and as it is exited (by any means, including exceptions and return statements), the __exit__ hook is called.

Python provides several standard context managers. File objects, for example, can be opened as a context manager, and on exit the file is automatically closed.

Context managers were defined in PEP 343.

Please use for the SQL WITH statement

1119 questions
-1
votes
1 answer

Getting column ambiguously defined when I shouldn't. Why?

I have two tables that return results when I put them together using UNION ALL, like this: SELECT * FROM TABLE_A UNION ALL SELECT * FROM TABLE_A But for some reason when I add this code into a WITH clause, like below, it does not work: WITH …
Zolt
  • 2,761
  • 8
  • 43
  • 60
-1
votes
3 answers

R: With function to read in subset of data based on column 1 == a value

In R, I need to read in a tab delimited text file, but only the rows where column 1 (strings) equals a specific string. I've been told I can do this using the with() function, but have not been able to accomplish it. I can do this in 2 statements,…
Alex B
  • 15
  • 4
-1
votes
1 answer

defining variable, invalid identifier. Euclidean Distance

oracle keeps rejecting anything i try call longitude within the with clause. WITH params as ( SELECT -28 as lat, 151 as lon FROM dual ) SELECT sighting_id FROM sightings ORDER BY sqrt(power(lat - latitude, 2) + power(lon -…
101ldaniels
  • 301
  • 1
  • 6
  • 15
-1
votes
1 answer

If columns match then

I have looked at several examples and I am confused as to what to use. I have 3 columns. If the data in all 3 columns(same line across) I would like it either to highlight the line or make some indicated that atleast one of the columns differ. What…
BEARY
  • 1
-1
votes
2 answers

keyword WITH for two queries

I want to do this : WITH temp (f1, f2, ...) BEGIN SELECT * FROM temp WHERE SELECT * FROM temp WHERE END but SQL Server raise error... is there any solution to do this ?
Atzi
  • 457
  • 1
  • 6
  • 16
-1
votes
1 answer

Filtering out unwanted entries from table

I have a table (really, a result of a query) that has the following attributes: Continent Group_name job_name status run_time For a given job, there can be a status of 'running', 'completed', or 'failed'. Sometimes, a job will fail, and then run…
DanGordon
  • 671
  • 3
  • 8
  • 26
-1
votes
2 answers

PEP343 'with' context manager and django

I am doing some application testing with django frame work , i have a case where i test if inactive users can login , and i do like so self.testuser.is_active = False //DO testing self.testuser.is_active = True //Proceed my question is , by…
AmOs
  • 129
  • 1
  • 13
-1
votes
1 answer

Several subqueries to WITH table in Oracle

Assuming i have the following table: create table Employee ( ID VARCHAR2(4 BYTE) NOT NULL, First_Name VARCHAR2(10 BYTE), Last_Name VARCHAR2(10 BYTE), Start_Date DATE, End_Date …
Fate
  • 3
  • 2
-1
votes
4 answers

Issue with "if" statement in Python

I have one file and I am trying to populate second file using its data in Python. While populating I am applying some if statements to manipulate one column in the 2nd file. What I want to perform using these if statements: Check 31st column in file…
atams
  • 2,739
  • 3
  • 16
  • 14
-1
votes
2 answers

What is with statement in php?

I just found this in a laravel bundle that I just installed, and really have no idea what with() is... as it isn't declared any where public static function of($query) { $ins = with(new static); // What is with(new static) ? …
Alex
  • 7,538
  • 23
  • 84
  • 152
-2
votes
0 answers

Integer value does not change

I have a For...Next statement with a With...End With statement inside. The integer that was supposed to hold the index for row count does not inherit the value of the counter. Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles…
-2
votes
1 answer

Counting up to 1,000 characters of a file

I am currently trying to count the characters per line and the first 1,000 characters of a txt file. My code counts the characters of the file and produces no error, but does not stop the count at 1,000. I know there needs to be a break to fix this…
JCPowell
  • 21
  • 2
-2
votes
2 answers

How to fix this code? i tried WITH statement but it gave me an error

I tried to answer this question here in the code below, but it keeps giving me an error message! I've tried to figure out how to Provide the name of the sales_rep in each region with the largest amount of total_amt_usd sales? and it gave me this…
Dolly
  • 1
  • 2
-2
votes
1 answer

get Specific columns in Spring

When I call the findAll() function in the result I get all the relation so I need to select the same columns. In Laravel they are used with() to resolve problm so What is the equivalent of the Laravel function in spring boot
-2
votes
1 answer

Keep context manager open after an if ... else statement

I have the following scheme, with different conditional with statements: if not remote: _open = open os.chdir(localpath) else: sftp = pysftp.Connection(host, username=user, password=sftppwd) with sftp: sftp.chdir(remotepath) …
Basj
  • 41,386
  • 99
  • 383
  • 673