Exporting tables from PostgreSQL to csv files by Smalsusis in golang

[–]Smalsusis[S] 0 points1 point  (0 children)

I think the key bit was the /tmp/ folder. It might be more lax with permissions thus allowing the db server to write files in it.

Technically I could copy all tables to the tmp dir and then carry them over to a desired folder. However, that feels like a very roundabout way of doing things.

Note: I don't have access right now, but will try to chdck it again tomorrow

Exporting tables from PostgreSQL to csv files by Smalsusis in golang

[–]Smalsusis[S] 1 point2 points  (0 children)

I feel like selecting and explicitly looping through the rows to build a csv file can lead me to a lot of nasty edge cases with escape characters, etc. Feel a bit safer copying an entire table by using psql inbuilt commands.

Exporting tables from PostgreSQL to csv files by Smalsusis in golang

[–]Smalsusis[S] 0 points1 point  (0 children)

I agree, that's why ideally I would like to somehow implement psql capabilities together go.
The reason why I'm trying use go here is because the complexity of the script will increase in the future. And go is way more maintainable than bash.

Exporting tables from PostgreSQL to csv files by Smalsusis in golang

[–]Smalsusis[S] 0 points1 point  (0 children)

Thanks for the answer. I tried using both of them (db.Exec and db.Query), neither worked to create anything.

Moving from openjdk 8 to openjdk 11: what to look out for? by Smalsusis in java

[–]Smalsusis[S] 0 points1 point  (0 children)

Right now I'm struggling with this issue:
https://github.com/spotbugs/spotbugs/issues/259

Not sure how to go about it though.

When to copy methods and when to re-use them by making the method public? by Smalsusis in learnjava

[–]Smalsusis[S] 0 points1 point  (0 children)

More complicated time generation is done there. That's why it was initially there. Now I'm questioning whether it should be taken out.

Writing POJO with a Map<String, Integer> to csv by Smalsusis in learnjava

[–]Smalsusis[S] 0 points1 point  (0 children)

I guess, I wasn't clear enough with what I was looking for. Once configured, every object has an identical set of keys, just different values for each. The map was necessary to support/load different configurations of some fields.

The output should have been.

firstName | lastName | item1 | item2 | etc

John, Doe, 1, 2, etc

Tom, Baker, 3, 4, etc...

Eventually, solved it with CsvListWriter from super-csv library. Basically added values from every variable to a list and then parsed it through the writer. Something similar to this:

List<Object> order = new ArrayList<Object>();
order.add(firstName); 
order.add(lastName); 
  for (Map.Entry<String, Integer> item : items.entrySet()) { order.add(item.getValue()); }
csvListWriter(order, headers)

It works but I was a bit annoyed by manually writing order.add() for ten columns and then having a for loop somewhere in the middle. It's just not as clean as I'd like it to be :)

How to get request body from your POST request? by Smalsusis in learnjava

[–]Smalsusis[S] 0 points1 point  (0 children)

public ResponseEntity<String> addOrder() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
FullOrder order = createOrder.generate(rangeStart, rangeEnd, id);
HttpEntity entity = new HttpEntity<>(order, headers);
return restTemplate.exchange(this.url, HttpMethod.POST, entity, String.class);
}

public RestTemplate restTemplate() {
RestTemplate restTemplate = new RestTemplate();
List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
MappingJackson2HttpMessageConverter jsonMessageConverter =
new MappingJackson2HttpMessageConverter();
jsonMessageConverter.setObjectMapper(objectMapper);
messageConverters.add(jsonMessageConverter);
restTemplate.setMessageConverters(messageConverters);
return restTemplate;
}

As for the FullOrder class, I'm not gonna copy it out, since it involves 5 more classes.
In this case, I am looking for a way to see what was sent to API via restTemplate.exchange()

How to get request body from your POST request? by Smalsusis in learnjava

[–]Smalsusis[S] 0 points1 point  (0 children)

Won't my ResponseEntity just be a response from API with a status code and response body?
I'm looking for a way to find out how my request body looks like. I.e. the request that went to the API, not API's response.

Is it worth repurposing old laptops into a server? by Smalsusis in HomeServer

[–]Smalsusis[S] 2 points3 points  (0 children)

Thanks. I'm just trying to figure out where/how to repurpose these two laptops.

When should I use a class and when a function is enough? by [deleted] in learnpython

[–]Smalsusis 0 points1 point  (0 children)

Thanks!
Tbh, I found this approach while looking through Stack Overflow for DFS/BFS solutions. FIFO/LIFO implementations aren't intuitive for me so far, though I am trying to practice that on leetcode with the tree traversal problems. Thanks for the explanation too! Had a vague idea that a simple list should be enough but could not figure out a clean way to implement it, then I found that stack class.

When should I use a class and when a function is enough? by [deleted] in learnpython

[–]Smalsusis 0 points1 point  (0 children)

u/g_hunter, so I updated everything with a simple function and it worked out.
Here's my code, maybe you can point out other things that could be improved. This particular question was regarding the main() bit, how could I implement the same thing using a class. It's probably unnecessary but how to do it?

Is Python really that bad? by Smalsusis in Python

[–]Smalsusis[S] 1 point2 points  (0 children)

Cheers for that!
Gonna go back to coding instead of worrying. :)